function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Darshit Pathak 10Darshit Pathak 10 

Why Cache.Session information gets deleted after few minutes?

I have created 1 default platform cache partition(genSys) with 5MB Session Cache.
Created 2 VF pages and one controller.

I am setting cache data on load of 1 VF Page and using that data in 2nd VF Page. But I lose data after 5 minutes. My understanding is that it should remain available 8 hours if browser is not closed during that period.
Can anyone help how can I maintain session cache for few hours?
 
Below is my code.
SessionHold.vfp
<apex:page controller="SessionHoldController" action="{!holdSeesionVars}">

</apex:page>

SesionGet.vfp
<apex:page controller="SessionHoldController" action="{!getSeesionVars}">
<h1>{!fnm} &nbsp; {!lnm}</h1>
</apex:page>

SessionHoldController.apxc
public with sharing class SessionHoldController {
    public static String fnm {get; set;}
    public static String lnm {get; set;}
    public SessionHoldController() {
    }
    public static void holdSeesionVars() {
        Cache.Session.put('local.gensysSession.firstName', 'ABC');
        String lnm = ApexPages.currentPage().getParameters().get('lnm');
        Cache.Session.put('local.gensysSession.lastName', lnm);
        System.debug(''+Cache.Session.MAX_TTL_SECS); //printing 28800
    }

    public static void getSeesionVars() {
        if (Cache.Session.contains('firstName')) {
            fnm = (String)Cache.Session.get('local.gensysSession.firstName');
        }
        if (Cache.Session.contains('lastName')) {
            lnm = (String)Cache.Session.get('local.gensysSession.lastName');
        }
        System.debug('Fnm: '+fnm+' lnm: '+lnm);
    }
}
 

VinayVinay (Salesforce Developers) 
Hi Darshit,

You need to check below 2 session settings.

>> Session Settings(Org Wide).
>> Profile level Session settings.

Review below links which can give more information.

https://help.salesforce.com/articleView?id=000317746&language=en_US&type=1&mode=1
https://help.salesforce.com/articleView?id=admin_sessions.htm&type=5
https://salesforce.stackexchange.com/questions/131333/session-expiry-in-salesforce-session-timeout-value-for-connected-apps

Thanks,
Vinay Kumar
Darshit Pathak 10Darshit Pathak 10

Thanks Vinay for responding.
But my profile level setting also sets user session time out to "24 hours of No Activity".

My problem is not that I am being logged out from salesforce.
Actual problem is.... the data I hold using Cache.Session get lost in few minutes only.
It should remain available till 8 hours.