Java ehcache disk storage

I am working on an application in which I need to create and often access thousands of files. For reasons of using disk space, I only want to keep a fixed number of these files at any given time. For example, files are written to the C: \ my-folder folder. When my folder reaches 1000 files, if I need to save a new file, I would like to delete the LRU file from my folder. Is such use of ehcache (or any caching tool) possible? I thought I could use disk storage in ehcache, but whenever I call getin the cache, it looks only at the keys that are in memory, not on the disk.

Below are some snippets of code:

    // 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");

Thank,

Jeff

+3
1

, EH Cache . 1000 , . EH Cache - .

. -. 1000 . , 1001, . , linux ... Linux, .

+2

Source: https://habr.com/ru/post/1765221/


All Articles