Newer Version Available

This content describes an older version of this product. View Latest

Platform Cache Considerations

Review these considerations when working with Platform Cache.
  • Cache isn’t persisted. There’s no guarantee against data loss.
  • Data in the cache isn’t encrypted.
  • Org cache supports concurrent reads and writes across multiple simultaneous Apex transactions. For example, a transaction updates the key PetName with the value Fido. At the same time, another transaction updates the same key with the value Felix. Both writes succeed, but one of the two values is chosen arbitrarily as the winner, and later transactions read that one value. However, this arbitrary choice is per key rather than per transaction. For example, suppose one transaction writes PetType="Cat" and PetName="Felix". Then, at the same moment, another transaction writes PetType="Dog" and PetName="Fido". In this case, the PetType winning value could be from the first transaction, and the PetName winning value could be from the second transaction. Subsequent get() calls on those keys would return PetType="Cat" and PetName="Fido".
  • Cache misses can happen. We recommend constructing your code to consider a case where previously cached items aren’t found.
  • Session cache doesn’t support asynchronous Apex. For example, you can’t use future methods or batch Apex with session cache.
  • Session cache doesn’t support Anonymous Apex blocks. For example, if you execute Anonymous Apex in the Developer Console, you get an error.
  • Cache operations made using the put and remove methods in the Cache Namespace aren’t supported in constructors of Visualforce controllers.
  • Partitions must adhere to the limits within Salesforce.
  • The session cache can store values up to eight hours. The org cache can store values up to 48 hours.