Salesforce Developer Platform Cache


Create partition
Cache Key Name Format
Using the platform cache
Eviction and expiration

// Salesforce - Developer - Platform Caches:

By default, your Developer org has 0-MB cache capacity. You can request trial 
cache of 10 MB.

To request a trial, go to Setup in your Developer Edition org. In the Quick 
Find box, enter cache, and then click Platform Cache. Click Request Trial 
Capacity and wait for a welcome email that notifies you that your Platform Cache 
trial is active. It can take up to 4 business days for your trial request to be 

Platform cache partitions let you segment the org's available cache space.  
Each partition's capacity is managed independently.  Request temporary platform 
cache trial capacity.  Once your trial request is approved, you can allocate 
capacity to partitions.  The maximum number of trial requests is 10 and orgs 
must wait 90 days between requests.

While you wait for your trail to be granted, you can still execute cache 
operations to learn how to use the cache. However, cache storage is bypassed and 
retrieved values are null (cache misses).

You can use Platform Cache in your code almost anywhere you access the same data 
over and over. Using cached data improves the performance of your app and is 
faster than performing SOQL queries repetitively, making multiple API calls, or 
computing complex calculations.  The best data to cache:

1. Reused throughout a session, or reused across all users and requests
2. Fairly Static (not rapidly changing)
3. Expensive to compute or retrieve

// Salesforce - Developer - Platform Caches - Cache Allocations by Edition:

Platform Cache is available to customers with Enterprise Edition orgs and above. 
The following editions come with some default cache space, but often, adding 
more cache gives even greater performance enhancements.

1. Enterprise Edition (10 MB by default)
2. Unlimited Edition (30 MB by default)
3. Performance Edition (30 MB by default)

You can purchase additional cache for your org. To determine how much extra 
cache would be beneficial for your applications, you can request trial cache 
and try it out. Also, request trial cache for Professional Edition before 
purchasing cache. Use trial cache in your Developer Edition org to develop and 
test your applications with Platform Cache. When your request is approved, you 
receive 30 MB of trial cache space (10 MB for Developer Edition). If you need 
more trial cache space, contact Salesforce.

// Salesforce - Developer - Platform Caches - Types of Platform Cache:

There are two types of Platform Cache: org cache and session cache.

1. Org Cache:  Org cache stores org-wide data that anyone in the org can use. 
   Org cache is accessible across sessions, requests, and org users and 
   profiles.  For example, weather data can be cached and displayed for contacts 
   based on their location. Or daily snapshots of currency exchange rates can be 
   cached for use in an app.

2. Session Cache: Session cache stores data for an individual user and is tied 
   to that user’s session. The maximum life of a session is 8 hours.  

// Salesforce - Developer - Platform Caches - Partitions:

Before you can use cache space in your org, you must create partitions to define 
how much capacity you want for your apps. Each partition capacity is broken down 
between org cache and session cache. Session and org cache allocations can be 
zero, 5 MB, or greater, and must be whole numbers. The minimum size of a 
partition, including its org and session cache allocations, is 5 MB. For example, 
say your org has a total of 10-MB cache space and you created a partition with a 
total of 5 MB, 5 MB of which is for session cache and 0 MB for org cache. Or you 
can create a partition of 10-MB space, with 5 MB for org cache and 5 MB for 
session cache. The sum of all partitions, including the default partition, 
equals the Platform Cache total allocation.

// Salesforce - Developer - Platform Caches - Default Partitioin:

You can define any partition as the default partition, but you can have only one 
default partition. The default partition enables you to use shorthand syntax to 
perform cache operations on that partition. This means that you don’t have to 
fully qualify the key name with the namespace and partition name when adding a 
key-value pair. For example, instead of calling: 

Cache.Org.put('namespace.partition.key', 0); 

you can just call:

 Cache.Org.put('key', 0);
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License