1

We are storing the auth token in the JCS, on restarting the server, the cache context got lost. In order to over come this, when stopping the server, decided to store the JCS list of values in to a file and When restarted, read the file and store it back to JCS. Please help me to store the JCS cache list in to file or any other possible solution.

I can't change the correct implementation of going out of storing the token in cache.

cache = JCS.getInstance("uniqueKey");
if (cache.get(key) == null) {
   cache.put(key, value);
}
Premanand K
  • 632
  • 8
  • 18

2 Answers2

1

While storing values in your cache you can add an auxiliary of indexedDiskCacheFactory. This will store the key and data in the directory configured in your cache.ccf file. Just add the following snippet for in your cache.ccf:

Regions preconfirgured for caching:

jcs.region.outputCache=DC
jcs.region.outputCache.cacheattributes.DiskUsagePatternName=UPDATE

Indexed Disk Path

jcs.auxiliary.DC=org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheFactory
jcs.auxiliary.DC.attributes=org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheAttributes
jcs.auxiliary.DC.attributes.DiskPath=d:/cache/dev/raf
jcs.auxiliary.DC.attributes.MaxKeySize=100000`

This should do the trick and once you restart your server the cache will take values from the file.

techdreams
  • 5,371
  • 7
  • 42
  • 63
Sabu22
  • 11
  • 1
0

Another thing to remember is to make sure the object you're storing implements Serializable.

I wasted a lot of time wondering why nothing was happening.