Can it be done?

2008-10-01
2013-05-14
  • Jeff Montreuil
    Jeff Montreuil
    2008-10-01

    Hi,

    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: http://sourceforge.net/projects/ehcache-zen/

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