Can it be done?

  • Jeff Montreuil

    Jeff Montreuil - 2008-10-01


    I'm using ehcache to store some data received from a webservice. When the data is expired, I call the service again to put a fresh value in the cache.

    I'm using a LRU policy, memory only cache to do this and, if I'm right, in that case the expired Element is removed from the cache when I get it using the cache.get("key") method (there is no expiry thread).

    The problem is the webservice could be down when I access it, and when this happens I would like to use the expired data.

    Is there a way to retrieve an entry from the cache even if it is expired and use the isExpired() method on it to see its validity?

    Thank you

    • Greg Luck

      Greg Luck - 2008-10-02

      No, but you could use a CacheEventListener, which gives you the element on expiry.

      You could also turn off expiry and create a Timer in a CacheExtension to periodically call the web service and overwrite the old value. It if fails nothing gets overwritten.

    • bhafer

      bhafer - 2009-07-15

      +1 for this feature.  I've just created a thread (3334621) with a few ideas about how to tackle this.

  • bhafer

    bhafer - 2010-01-28

    Hello again.  It took a long time to get the time for it, but I've finally implemented an ExpiredBetterThanNullSelfPopulatingCache and some other features. 

    I've started a SourceForge project:

    Please check it out and let me know on the forums there your feedback.


Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks