I have setup a Memcache using the JCache API to interface with it. The cache is built as follows:
import javax.cache.Cache;
import javax.cache.CacheException;
import javax.cache.CacheManager;
TreeMap<String, String> name2Id = Maps.newTreeMap();
...
if (cache == null) {
@SuppressWarnings("rawtypes")
Map properties = Collections.emptyMap();
cache = CacheManager.getInstance().getCacheFactory().createCache(properties);
CacheManager.getInstance().registerCache(dropDownCache, cache);
log.fine("Registering cache: " + dropDownCache);
}
cache.put(innerCache, name2Id);
My cache is registered with the name "dropDownCache". The cache contains a single key, "innerCache" with a value containing a map. The map contains a set of key,values that represent the indexed contents for a dropdown menu.
I have a cron job/task that hits the cache every minute to make sure that the cache is not evicted. According to the documentation, I do not believe I should need to do this because I did not specify an eviction time, so keys should never expire. However, it does show me that over a long period of time, the cache is rarely evicted.
The problem is that when myself, or another user, actually visits the page on the webapp with the dropdown menu. When the page comes up, the dropdown menu ends up loading from the datastore because the registered cache is no longer there. The cache ends up missing very often and I do not understand why this is such a stark contrast to what I am seeing with my cron job/task.
Maybe storing a Map as a key is inappropriate? It seems reasonable though.
Any help to figure out why my cache is being evicted would be great help. Or is there a way to figure out exactly why it's being evicted?