Use a Visualforce Global Variable for the Session Cache

Access cached values stored in the session cache from a Visualforce page by using the $Cache.Session global variable.
Note

Note

The Visualforce global variable is currently available only for the session cache and not for the org cache.

When using the $Cache.Session global variable, fully qualify the key name with the namespace and partition name. This example is an output text component that retrieves a cached value from the namespace myNamespace, partition myPartition, and key key1.

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

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

Use local instead of the namespace name to refer to the org’s namespace, whether or not a namespace is defined for the org.

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

If the cached value is a data structure that has properties or methods, like an Apex List or a custom class, those properties can be accessed in the $Cache.Session 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.

<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.

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