Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1065983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T19:56:53+00:00 2026-05-16T19:56:53+00:00

I’m working on application in which I need to generate and frequently access thousands

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T19:56:54+00:00Added an answer on May 16, 2026 at 7:56 pm

    This doesn’t seem like you are using EH Cache to it’s potential.. to store 1000 items on disk and then rotate away the last used one. EH Cache is more for storing stuff in memory, and using disk as a backup when memory fills.

    I would personally just roll my own. You have very specific business rules. Store 1000 items. Then when you are ready to store file 1001, you could go and find a file to delete. If you have access time turned on at the OS level, you can do a single linux command to delete the least recently accessed file… Usually you don’t use access time for files in linux, but it would make your problem easy to solve at the OS level..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.