8

I'd like to implement the following algorythm above Ehcache :

  • try to get an element from the cache
  • if the element is not expired
    • serve the value
  • else
    • serve the expired value
    • refresh the element in the background

But I never get an expired element (Element.isExpired()). I tried to play with my cache configuration (especially TimeToLive and TimeToIdle) but I cant seem to get it to work as I want. I can list the keys in the cache, but if I "get()" an expired element, I always get a null.

What am I doing wrong ?

1
  • 1
    Just curious, did you ever come up with a solution or an alternate approach to this?
    – Avi Flax
    Mar 11, 2011 at 0:11

1 Answer 1

4

You're not doing anything wrong. The documentation says that getting an expired element will remove it from the cache and return null.

I suspect the only time an element will come up as expired is if you have an event listener listenings for element expiry events but I can't say I've ever tested this.

1
  • Pay attention with the event listener (notifyElementExpiry). Only the key of the element is kown. According to following sentence in the API: As the Element has been expired, only what was the key of the element is known. Just had trouble with this.
    – schoeggii
    Nov 1, 2012 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.