Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
public class UserAccountsCacheDataBuilder extends CacheDataBuilder
{
	protected List initializeCache(HashMap params)
		{
			SessionInfo sessInfo = (SessionInfo)params.get(CacheConstants.OBJECT_SESSIONINFO);
			String userNumber = sessInfo.userNo;
			String gcif = sessInfo.sCustNo;
			// Execute your logic to get the list of accounts linked to this user.
			List<AccountVO> userAccounts = getUserAccountsFor(userNumber, gcif);
			return userAccounts;
		}
} 


Now that we have the CacheDataBuilder ready, let us proceed to define the cache as follows:

Code Block
languagexml
<Cache Id="USER_ACCOUNTS_CACHE" Scope="session">
	<Handler>com.myapplication.UserAccountsCacheDataBuilder </Handler>
</Cache> 

...

Code Block
languagejava
List<AccountVO> userData = CacheManager.getInstance().getDataFromCache(session, "USER_ACCOUNTS_CACHE");
	for (AccountVO obj : userData)
		{
			//Perform your application logic here...
		} 


The key aspect around Session Cache is that the data for the Session cache is stored in a key that is dynamically created in the Session. Hence, it is necessary to always pass the HttpSession object for retrieving data from this cache.

...