Continuing with Platform Cache….
2. Org Cache : The second variant of Platform Cache is the Org Cache. Org Cache does the same thing of storing the data in session, but the data stored is accessible through out the org, irrespective of user, which is not the case with Session Cache.
If user1 is storing a value1 in org cache, it is accessible by user2 also.
We can have different partitions to store values. We use the Cache.Org and Cache.OrgPartition classes to manage values in the org cache. To manage values in any partition, use the methods in the Cache.Org class. If we are managing cache values in one partition, use the Cache.OrgPartition methods instead.
This example stores a DateTime cache value with the key orderDate. Next, the snippet checks if the orderDate key is in the cache, and if so, retrieves the value from the cache.
}
To refer to the default partition and the namespace of the invoking class, omit the namespace.partition prefix and specify the key name.
Cache.Org.put(‘orderDate’, dt);
if (Cache.Org.contains(‘orderDate’)) {
DateTime cachedDt = (DateTime)Cache.Org.get(‘orderDate’);
}
The local prefix refers to the namespace of the current org where the code is running. The local prefix refers to the namespace of the current org where the code is running, regardless of whether the org has a namespace defined. If the org has a namespace defined as ns1, the following two statements are equivalent.
Cache.Org.put(‘ns1.myPartition.orderDate’, dt);
This is all about the Org Cache in apex. There is another interesting thing about Platform Cache!
This output text component retrieves a session cache value using the global variable’s namespace, partition, and key.
This example is similar but uses the $Cache.Org global variable to retrieve a value from the org cache.
<apex:outputTextvalue=”{!$Cache.Org.myNamespace.myPartition.key1}”/>
Now the Platform Cache concept seems more useful! We can directly use it in Vf page!!
Salesforce is Awesome!