I have create small function to store and retrieve the value inside static using session cache. but i am unable to get the data which i have stored in session cache. I am not getting any error on retrieve or inserting but Always return null value. Any one can help me.
Here is My platform Cache setting
Apex Controller :
public class SessionCacheController {
public static String name {get;set;}
public static String check {get;set;}
public static String dummy {get;set;}
private static final String KEY = 'Key';
private static final String VALUE = 'Any value';
//adding key,value pair to cache
public static void setData()
{
dummy='setData';
Cache.Session.put('MyPackagePrefix.PlatformCache.myName', 'Nithesh K');
Cache.Partition partition = Cache.Session.getPartition('PlatformCache');
partition.put(KEY, VALUE);
}
//retrieve value by key
public static void getData()
{
dummy='getData';
Name=(String)Cache.Session.get('MyPackagePrefix.PlatformCache.myName');
system.debug('myName *** ' + Name); // return null
Cache.Partition partition = Cache.Session.getPartition('PlatformCache');
check = (String) partition.get(KEY);
system.debug('check *** ' + check); // return null
}
}
Visual force Page
<apex:page controller="SessionCacheController">
<apex:form >
<apex:pageBlock id="pageSection">
<apex:outputText > My name {! Name } </apex:outputText> <br/>
<apex:outputText > Check Key {! check } </apex:outputText> <br/>
<apex:outputText > dummy {! dummy } </apex:outputText> <br/>
</apex:pageBlock>
<apex:commandButton value="setData" action="{!setData }" reRender="pageSection"/>
<apex:commandButton value="getData" action="{!getData }" reRender="pageSection"/>
</apex:form>
</apex:page>
When i click setData() command-button, Value is added cache.session and getData() value is retrieve from cache.session and render in visual force page .