I'm working on application in which I need to generate and frequently access thousands of files. For disk space usage reasons, I only want to keep around a fixed number of these files at any given time. For example, the files are being written to C:\my-folder. Once my-folder reaches 1000 files, if I need to save a new file, I would like to erase the LRU file from my-folder. Is something like this possible using ehcache (or any caching tool)? I thought I could use a disk store in ehcache, but whenever I call get
on the cache, its only looking at the keys that are in memory and not in disk.
Some snippets of my code are shown here:
// create the cache
CacheManager cm = CacheManager.create();
String name = getName();
CacheConfiguration config = new CacheConfiguration(name, 1)
.maxElementsOnDisk(2000).diskPersistent(true)
.overflowToDisk(true).eternal(true).diskStorePath(name)
.memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LRU);
Cache cache = new Cache(config);
cm.addCache(cache);
// I do a couple of puts
cache.put(new Element("key1", val1));
cache.put(new Element("key2", val2));
cache.flush();
// now key1 is no longer in the cache (since max memory size is 1), but I'd like to look on disk since I have set maxElementsOnDisk to 2000
Element el = cache.get("key1");
Thanks,
Jeff