Skip to main content
paragraphs added (please avoid such big-walls-of-text)
Source Link
Doc Brown
  • 220.7k
  • 35
  • 410
  • 625

I have an App that connects with Salesforce and do different operations. So I'm trying to implement a Session Cache for the Application to avoid repetitive login calls. 

So far what I have done is I have created a ConcurrentHashMap which stores a Session Object (object consists of SessionID, CreatedTime, Validity, ServiceURL etc.) When a new request comes in I get the Session object from the HashMap, check the validity of the session and if valid return the session. 

Recently I learned that Salesforce session is like a user Session, as long as you do requests with the Same sessionID it's kept active, if you idle for X amount of time it expires. So I'm thinking of the best way to implement this. 

Initially I thought of adding a new field like lastAccessTime to the Session object and validate based on this. But the problem is since my App is a highly concurrent application which handles many requests, each time a request comes-in I will be retrieving the session updating lastAccessTime and adding back to the HashMap, which feels like a overhead. 

Is there any better way to do this  (I was thinking may be maintain two HashMaps, one for the Session Object, one for the lastAccessTime)? Or can I can simply ignore the fact that session is updated on access and stick to the initial session generated. Probably I would do more requests to Salesforce but between updating the session Map on each request I would feel that's more efficient.

I have an App that connects with Salesforce and do different operations. So I'm trying to implement a Session Cache for the Application to avoid repetitive login calls. So far what I have done is I have created a ConcurrentHashMap which stores a Session Object (object consists of SessionID, CreatedTime, Validity, ServiceURL etc.) When a new request comes in I get the Session object from the HashMap, check the validity of the session and if valid return the session. Recently I learned that Salesforce session is like a user Session, as long as you do requests with the Same sessionID it's kept active, if you idle for X amount of time it expires. So I'm thinking of the best way to implement this. Initially I thought of adding a new field like lastAccessTime to the Session object and validate based on this. But the problem is since my App is a highly concurrent application which handles many requests, each time a request comes-in I will be retrieving the session updating lastAccessTime and adding back to the HashMap, which feels like a overhead. Is there any better way to do this(I was thinking may be maintain two HashMaps, one for the Session Object, one for the lastAccessTime)? Or I can simply ignore the fact that session is updated on access and stick to the initial session generated. Probably I would do more requests to Salesforce but between updating the session Map on each request I would feel that's more efficient.

I have an App that connects with Salesforce and do different operations. So I'm trying to implement a Session Cache for the Application to avoid repetitive login calls. 

So far what I have done is I have created a ConcurrentHashMap which stores a Session Object (object consists of SessionID, CreatedTime, Validity, ServiceURL etc.) When a new request comes in I get the Session object from the HashMap, check the validity of the session and if valid return the session. 

Recently I learned that Salesforce session is like a user Session, as long as you do requests with the Same sessionID it's kept active, if you idle for X amount of time it expires. So I'm thinking of the best way to implement this. 

Initially I thought of adding a new field like lastAccessTime to the Session object and validate based on this. But the problem is since my App is a highly concurrent application which handles many requests, each time a request comes-in I will be retrieving the session updating lastAccessTime and adding back to the HashMap, which feels like a overhead. 

Is there any better way to do this  (I was thinking may be maintain two HashMaps, one for the Session Object, one for the lastAccessTime)? Or can I simply ignore the fact that session is updated on access and stick to the initial session generated. Probably I would do more requests to Salesforce but between updating the session Map on each request I would feel that's more efficient.

Source Link

Optimal way Implement a Session Cache

I have an App that connects with Salesforce and do different operations. So I'm trying to implement a Session Cache for the Application to avoid repetitive login calls. So far what I have done is I have created a ConcurrentHashMap which stores a Session Object (object consists of SessionID, CreatedTime, Validity, ServiceURL etc.) When a new request comes in I get the Session object from the HashMap, check the validity of the session and if valid return the session. Recently I learned that Salesforce session is like a user Session, as long as you do requests with the Same sessionID it's kept active, if you idle for X amount of time it expires. So I'm thinking of the best way to implement this. Initially I thought of adding a new field like lastAccessTime to the Session object and validate based on this. But the problem is since my App is a highly concurrent application which handles many requests, each time a request comes-in I will be retrieving the session updating lastAccessTime and adding back to the HashMap, which feels like a overhead. Is there any better way to do this(I was thinking may be maintain two HashMaps, one for the Session Object, one for the lastAccessTime)? Or I can simply ignore the fact that session is updated on access and stick to the initial session generated. Probably I would do more requests to Salesforce but between updating the session Map on each request I would feel that's more efficient.