Search code examples
springehcache

How not expire cache if it can't retrieve data


I'm caching some data from a WebService. My cache has an expiry date but how prevent clearing when the WebService is down and it is impossible to retrieve data ?

<cache name="mySuperCache"
    maxElementsInMemory="50"
    eternal="false"
    timeToLiveSeconds="3600"
/>

@Cacheable(value = "mySuperCache")
public Response callWebService() {
    //call api
}

Solution

  • There is no built-in support for what you ask in Ehcache.

    If that's a desired behaviour for your application, you may have to cache data structures that keep track of their expiry and are able to serve the old version based on application specific conditions.