Newer Version Available

This content describes an older version of this product. View Latest

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.

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

Note

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.

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

If a namespace is not defined for the org, use local to refer to the org’s namespace.

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

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}"/>