Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.

Use a Visualforce Global Variable for the Platform Cache

You can access cached values stored in the session or org cache from a Visualforce page with global variables.

You can use either the $Cache.Session or $Cache.Org global variable. Include the global variable’s fully qualified key name with the namespace and partition name.

This output text component retrieves a session cache value using the global variable’s namespace, partition, and key.

1<apex:outputText value="{!$Cache.Session.myNamespace.myPartition.key1}"/>

This example is similar but uses the $Cache.Org global variable to retrieve a value from the org cache.

1<apex:outputText value="{!$Cache.Org.myNamespace.myPartition.key1}"/>

The remaining examples show how to access the session cache using the $Cache.Session global variable. The equivalent org cache examples are the same except that you use the $Cache.Org global variable instead.

Note

Unlike with Apex methods, you can’t omit the myNamespace.myPartition prefix to reference the default partition in the org.

If a namespace isn’t defined for the org, use local to refer to the org’s namespace.

1<apex:outputText value="{!$Cache.Session.local.myPartition.key1}"/>

The cached value is sometimes a data structure that has properties or methods, like an Apex list or a custom class. In this case, you can access the properties in the $Cache.Session or $Cache.Org expression by using dot notation. For example, this markup invokes the List.size() Apex method if the value of numbersList is declared as a List.

1<apex:outputText value="{!$Cache.Session.local.myPartition.numbersList.size}"/>

This example accesses the value property on the myData cache value that is declared as a custom class.

1<apex:outputText value="{!$Cache.Session.local.myPartition.myData.value}"/>

If you’re using CacheBuilder, qualify the key name with the class that implements the CacheBuilder interface and the literal string _B_, in addition to the namespace and partition name. In this example, the class that implements CacheBuilder is called CacheBuilderImpl.

1<apex:outputText value="{!$Cache.Session.myNamespace.myPartition.CacheBuilderImpl_B_key1}"/>