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?
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.
+1 for this feature. I've just created a thread (3334621) with a few ideas about how to tackle this.
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.