Improve Performance and Reliability with Platform Cache

Utilize the new Force.com platform caching layer to cache Salesforce session and org data for faster performance and better reliability. The Cache namespace in Apex lets you specify what to cache and for how long, without needing to use custom objects and settings or overloading a Visualforce viewstate. Also use org partitions to improve performance by distributing cache space so some apps or operations don’t steal capacity from others. This feature is available in both Lightning Experience and Salesforce Classic.
There are two types of cache:
  • Session cache—Stores data for individual user sessions. For example, in an app that finds customers within specified territories, the calculations that run while users browse different locations on a map are reused.

    A session cache lives alongside a user session. The maximum life of a session is eight hours. A session cache expires when its specified time-to-live (ttlsecs value) is reached or when the session expires after eight hours, whichever comes first.

  • Org cache—Stores data that any user in an org reuses. For example, the contents of navigation bars that dynamically display menu items based on user profile are reused.

    Unlike a session cache, an org cache is accessible across sessions, requests, and org users and profiles. An org cache expires when its specified time-to-live (ttlsecs value) is reached.

Session data is cached alongside user sessions. Org data is accessible across sessions, requests, and org users. The session cache expires when its specified time-to-live (ttlsecs value) is reached, or when the session expires, whichever comes first. Because Apex runs in a multitenant environment with cached data living alongside internally cached data, there’s minimal disruption to core Salesforce processes.

Easily set up and manage partitions with the Platform Cache Partition tool in Setup, without using Apex code. Use the tool to create or remove cache partitions, and allocate their cache capacities to balance performance across apps. The tool displays a snapshot of all partitions with their allotted capacities, and lets you reallocate space as needed.

Note

Note

To use caching, you need at least one partition in your org. Optionally, create multiple partitions and designate one as the default partition.

To access the Partition tool in Setup, enter Platform Cache in the Quick Find box, then select Platform Cache.

The Cache namespace includes classes and methods for managing your org’s cache space programmatically. Use five specialized Apex classes to:

  • Add, retrieve, and manage values in the session cache or the org cache.
  • Manage cache values in the org cache of a specific partition.
  • Manage cache values in the session cache of a specific partition.
  • Get a specific partition in order to perform cache operations.
  • Perform cache operations on a default partition without having to use fully qualified key references.

For information about managing cache space and behavior with Apex, see the Force.com Apex Code Developer’s Guide. For information about the new Metadata API type for partitions, see the Metadata API Developer’s Guide.