Partitions for Data Cached with Platform Cache

Partitions improve application performance by distributing cache space in the best way for your org. Cache data to designated partitions to ensure that it’s not overwritten by other applications or less-critical data. Create and manage org partitions declaratively by using the Platform Cache Partition tool in Setup.

Partitions are integral to the API, and cache capability depends on them. To use the platform cache, you need at least one partition. Each partition has one session cache and one org cache segment. Each cache segment has its own capacity and time-to-live attributes and uses an LRU algorithm.

Use the Platform Cache Partition tool to:

  • Create or remove org partitions.
  • Allocate the session cache and org cache capacities of each partition to balance performance across apps.
  • View a snapshot of all cache partitions with their current and total capacities.
  • View details about each partition.
  • Make any partition the default partition, for example to use via static methods.

First create at least one partition and allocate cache capacity to that partition’s session cache and org cache segments. You can distribute your org’s cache space across any number of partitions. Session and org cache allocations can be zero or greater than five and must be whole numbers. The sum of all partition allocations, including the default partition, equals the platform cache total allocation. The total allocated capacity of all cache segments must equal or be less than the org’s overall capacity.

You can have only one default partition, but you can define any partition as the default partition. When the capacity of the default partition is used up and is zero, you can’t create any more partitions. When a partition has no capacity left, cache operations aren’t performed, and no error is returned.

When performing cache operations within the default partition, you can omit the partition name from the key.

*If platform cache code is intended for a package, we recommend not using the default partition in the package. Instead, explicitly reference and package a non-default partition.

View the org’s capacity allocation on the Platform Cache Partition page. To access the Partition tool in Setup, enter Platform Cache in the Quick Find box, then select Platform Cache.

platform cache.PNG

Capacity calculations occur every five minutes by default. To make sure you’re seeing the latest capacity and allocation, click Force Refresh Capacity.

Platform Cache Considerations

There are a few considerations for using platform cache features.

  • Cache is not persisted. There is no guarantee against data loss.
  • Data in the cache is not encrypted.
  • The cache doesn’t support concurrent operations. Multiple, simultaneous user requests (for example, from different browser windows) can lead to stale or overwrritten data in the cache.
  • Cache misses can happen. We recommend constructing your code to consider a case where previously cached items aren’t found.
  • The session cache isn’t supported in Anonymous Apex blocks. For example, if you execute Anonymous Apex in theDeveloper Console, you’ll get an error.
  • Cache operations made using the Cache Namespace aren’t supported in constructors of Visualforce controllers.
  • Partitions are bound by the limits within Salesforce.
  • The session cache can store values for a maximum of eight hours and the org cache can store values for a maximum of 48 hours.


Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome content in your inbox, every month.

We don’t spam! Please check your mail for confirmation.

Leave a Comment

Your email address will not be published. Required fields are marked *

Select Language »