To use the Force.com platform cache, you need at least one partition. You can distribute your org’s cache space across any number of partitions. 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.
First create at least one partition and then allocate cache capacity to that partition’s session cache and org cache segments. 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 be less than or equal to the org’s overall capacity.
You can define any partition as the default partition, but you can have only one default partition. When the capacity of the default partition is used up and is zero, you can’t create more partitions. When a partition has no more capacity, cache operations are not performed and no error is returned.
When performing cache operations within the default partition, you can omit the partition name from the key.
If you’re working with managed packages, we recommend using Branch Packaging Orgs to share a namespace across partitions. This feature lets you maintain multiple orgs or partitions as “branches” of your primary org. It eliminates the need to fully qualify key names when referencing partitions. For information about Branch Packaging Orgs, contact Salesforce.
After you set up partitions, you can use Apex code to perform cache operations on a partition. For example, use the Session.Partition and Org.Partition classes to put, retrieve, or remove values on a specific partition’s cache. Use Cache.Session and Cache.Org to get a partition or perform cache operations by using a fully qualified key.