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

  • SEARCH
  • Home
  • 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 7160497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:24:33+00:00 2026-05-28T13:24:33+00:00

I’m trying to configure Ehcache (version 2.5) such that it never forgets items. I’m

  • 0

I’m trying to configure Ehcache (version 2.5) such that it never forgets items. I’m configuring programmatically and I haven’t touched any of the configuration XML files. By setting eternal to true it is my understanding that the only circumstances under which an item could be removed from the cache would be if I run out of disk space or exceed maxBytesLocalDisk (or if the application terminates). However, this test program does not show that behavior:

public static void main(String[] args) {
  CacheManager cacheManager = CacheManager.create(); 
  Cache cache = new Cache(
    new CacheConfiguration().name("test")
    .overflowToDisk(true)
    .eternal(true)
    .maxBytesLocalHeap(1, MemoryUnit.MEGABYTES)
    .overflowToOffHeap(false)
    .maxBytesLocalDisk(100, MemoryUnit.GIGABYTES)
    .maxElementsOnDisk(0)
    .timeToIdleSeconds(0)
    .timeToLiveSeconds(0)
    .diskStorePath("E:\\Data\\Ehcache"));
  cacheManager.addCache(cache);
  for(int i = 0; i < 1000000; i++){
    cache.put(new Element("key_" + i, "value_" + i));
  }
  System.out.println(cache.getSize());      
}

So after adding 1 million elements to my cache, which I told to overflow to a disk that is large enough by orders of magnitude, I only end up with 3276 items at the end. What is happening here?

  • 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-28T13:24:33+00:00Added an answer on May 28, 2026 at 1:24 pm

    When using ARC, or byte based cache configuration, Ehcache will try to protect your system of an OOME. Configuring the cache as you did, tells ehcache that you want this cache to use at most 1 megabyte of heap. Overflowing to disk tells Ehcache to overflow elements to disk when the heap is filled to the threshold. Now, the key set for this cache will still remain on heap. And, as Ehcache still tries to protect you from OOME, it will need to evict from disk, as soon as the key set can’t be held in memory anymore.

    I slightly changed your config to use 10MB, I can get 32K entries in the Cache. If I change your key to be smaller (only the Integer instance), I can get 46K entries in the Cache. But basically, this configuration your using is to restrictive, as Ehcache will never be able to hold that much on disk, with the key set on heap. Hope this clarifies a bit.

    If you really have a use case where you need to put a lot on disk and minimize on-heap storage, you might want to look into http://ehcache.org/documentation/user-guide/storage-options#enterprise-diskstore

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

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.