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 8508329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:07:57+00:00 2026-06-11T03:07:57+00:00

I’m using Ehcache to cache objects that are very expensive to load in my

  • 0

I’m using Ehcache to cache objects that are very expensive to load in my application. On start-up I cache all the needed objects and they get refreshed once a day by a separate process.

However, it appears that shortly after I add objects to the cache, they disappear. Nothing is being reported as being evicted, but the objects aren’t lasting in the cache for some reason. When I run ObjectLoader.loadCache() this is the output I’m receiving:

2012-09-01 17:25:37,121 [main] DEBUG ObjectLoader.getObject():65 - ************************************
2012-09-01 17:25:37,121 [main] DEBUG ObjectLoader.getObject():66 - Number of objects in cache: 0
2012-09-01 17:25:37,121 [main] DEBUG ObjectLoader.getObject():72 - Object not in cache | 501
2012-09-01 17:26:17,271 [main] DEBUG ObjectLoader.getObject():80 - Number of objects in cache: 1
2012-09-01 17:26:17,271 [main] DEBUG ObjectLoader.getObject():81 - Number of objects evicted from cache: 0
2012-09-01 17:26:17,274 [main] DEBUG ObjectLoader.getObject():83 - Object key found: 501
2012-09-01 17:26:17,274 [main] DEBUG ObjectLoader.getObject():65 - ************************************
2012-09-01 17:26:17,274 [main] DEBUG ObjectLoader.getObject():66 - Number of objects in cache: 1
2012-09-01 17:26:17,274 [main] DEBUG ObjectLoader.getObject():72 - Object not in cache | 518
2012-09-01 17:26:35,894 [main] DEBUG ObjectLoader.getObject():80 - Number of objects in cache: 1
2012-09-01 17:26:35,895 [main] DEBUG ObjectLoader.getObject():81 - Number of objects evicted from cache: 0
2012-09-01 17:26:35,895 [main] DEBUG ObjectLoader.getObject():83 - Object key found: 518
2012-09-01 17:26:35,895 [main] DEBUG ObjectLoader.getObject():65 - ************************************
2012-09-01 17:26:35,895 [main] DEBUG ObjectLoader.getObject():66 - Number of objects in cache: 1
2012-09-01 17:26:35,895 [main] DEBUG ObjectLoader.getObject():72 - Object not in cache | 516
2012-09-01 17:27:31,997 [main] DEBUG ObjectLoader.getObject():80 - Number of objects in cache: 1
2012-09-01 17:27:31,998 [main] DEBUG ObjectLoader.getObject():81 - Number of objects evicted from cache: 0
2012-09-01 17:27:31,998 [main] DEBUG ObjectLoader.getObject():83 - Object key found: 516
2012-09-01 17:27:31,998 [main] DEBUG ObjectLoader.getObject():65 - ************************************
2012-09-01 17:27:31,998 [main] DEBUG ObjectLoader.getObject():66 - Number of objects in cache: 1
2012-09-01 17:27:31,998 [main] DEBUG ObjectLoader.getObject():72 - Object not in cache | 515
2012-09-01 17:28:20,343 [main] DEBUG ObjectLoader.getObject():80 - Number of objects in cache: 1
2012-09-01 17:28:20,343 [main] DEBUG ObjectLoader.getObject():81 - Number of objects evicted from cache: 0
2012-09-01 17:28:20,344 [main] DEBUG ObjectLoader.getObject():83 - Object key found: 515
2012-09-01 17:28:20,344 [main] DEBUG ObjectLoader.getObject():65 - ************************************
2012-09-01 17:28:20,344 [main] DEBUG ObjectLoader.getObject():66 - Number of objects in cache: 1
2012-09-01 17:28:20,344 [main] DEBUG ObjectLoader.getObject():72 - Object not in cache | 525
2012-09-01 17:29:05,616 [main] DEBUG ObjectLoader.getObject():80 - Number of objects in cache: 1
2012-09-01 17:29:05,617 [main] DEBUG ObjectLoader.getObject():81 - Number of objects evicted from cache: 0
2012-09-01 17:29:05,617 [main] DEBUG ObjectLoader.getObject():83 - Object key found: 525
2012-09-01 17:29:05,617 [main] DEBUG ObjectLoader.getObject():65 - ************************************
2012-09-01 17:29:05,617 [main] DEBUG ObjectLoader.getObject():66 - Number of objects in cache: 1
2012-09-01 17:29:05,618 [main] DEBUG ObjectLoader.getObject():72 - Object not in cache | 512
2012-09-01 17:29:38,790 [main] DEBUG ObjectLoader.getObject():80 - Number of objects in cache: 1
2012-09-01 17:29:38,790 [main] DEBUG ObjectLoader.getObject():81 - Number of objects evicted from cache: 0
2012-09-01 17:29:38,790 [main] DEBUG ObjectLoader.getObject():83 - Object key found: 512

Do I have ehcache configured wrong or do I have a bug in my code? Any help would be appreciated. Thanks.

I’m using spring 3.1.0, ehcache-spring-annotations 1.1.2, and ehcache 2.4.2

ObjectCacheFacade.java

@Component()
public class ObjectCacheFacade {
    private static final String CACHE_KEY = "myObjectCache";

    @Resource
    private CacheManager cacheManager;
    private Cache cache;

    public ObjectCacheFacade() {
        cacheManager = CacheManager.getInstance();
        this.cache = cacheManager.getCache(CACHE_KEY);
    }

    public Object getObjectFromCache(String objectId) {
        Object result = null;
        Element element = cache.get(objectId);

        if (element != null && element.getValue() != null) {
            result = element.getObjectValue();
        } 

        return result;
    }

    public void putObjectIntoCache(String objectId, Object object) {
        Element element = new Element(objectId, object);
        cache.put(element);
    }

    public int getSize() {
        return cache.getSize();
    }

    public void removeObjectFromCache(String objectId) {
        cache.remove(objectId);
    }

    public void flushCache() {
        cache.removeAll();
    }

    public Cache getCache() {
        return cache;
    }
}

ObjectLoader.java

@Service
public class ObjectLoader {
    private static final Logger log = Logger.getLogger(ObjectLoader.class);

    @Resource
    protected ObjectDao objectDao;
    @Resource
    protected ObjectCacheFacade objectCache;

    public void loadCache() {
        List<String> objectIds = objectDao.getObjectIds();

        for (String objectId : objectIds) {
            loadObject(objectId);
        }
    }

    public Object getObject(String objectId) {
        log.debug("************************************");
        log.debug("Number of objects in cache: " + objectCache.getSize());

        Object object = objectCache.getObjectFromCache(objectId);

        if (object == null) {
            log.debug("Object not in cache | " + objectId);
            object = objectDao.getObject(objectId);

            if (object != null) {
                objectCache.putObjectIntoCache(objectId, object);

                log.debug("Number of objects in cache: " + objectCache.getSize());
                log.debug("Number of objects evicted from cache: " + objectCache.getCache().getCacheEventNotificationService().getElementsEvictedCounter());
                for (Object key : objectCache.getCache().getKeys()) {
                    log.debug("Object key found: " + key);
                }
            } 
        } 

        return object;
    }
}

ehcache.xml

<ehcache>
    <diskStore path="java.io.tmpdir"/>

    <defaultCache
        maxElementsInMemory="1000"
        eternal="false"
        timeToIdleSeconds="60"
        timeToLiveSeconds="300"
        overflowToDisk="false"
        memoryStoreEvictionPolicy="LRU"
       />

    <cache
        name="myObjectCache"
        maxElementsInMemory="1000"
        eternal="true"
        timeToIdleSeconds="0"
        timeToLiveSeconds="0"
        overflowToDisk="false"
        diskPersistent="true"
        memoryStoreEvictionPolicy="LRU"
       />

</ehcache>

applicationContext.xml

<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" />
  • 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-06-11T03:07:59+00:00Added an answer on June 11, 2026 at 3:07 am

    Since diskPersistent was set to true Ehcache was attempting to write the objects to disk after they were added to the cache. However, one of the nested objects inside the main cached object didn’t implement Serializable, so it was throwing an exception on disk write and then evicting the object from the cache. This eviction wasn’t showing up in the cache statistics since it wasn’t evicted by the memoryStoreEvictionPolicy.

    This should have been an very easy bug to find, but the project didn’t include the slf4j-log4j12 library, so the exception was being swallowed instead of being written out to the logs. Once the logging was handled properly, it was instantly obvious what the problem was.

    Oh well, live and learn I guess…

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

Sidebar

Related Questions

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'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am reading a book about Javascript and jQuery and using one of the
I've got a string that has curly quotes in it. I'd like to replace
Specifically, suppose I start with the string string =hello \'i am \' me And
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.