Image making a Spring service, in the following manner:
+--------+ +---------+ +---------+ |Backend | --------- | My | ----------- | Clients | |service | | service | | | +--------+ +---------+ +---------+
In order not to make too much requests to the backend, I use Ehcache.
Imagine that my service is a sports portal, and I cache the results so that when a client requests them, I return the cache, if there’s no cache, I fetch the info from backend, put it in cache, and then return it to the client.
Now, If I have these parameters set
long timeToLiveSeconds
long timeToIdleSeconds
and the clients make requests too often, the timeToIdleSeconds won’t expire, but the timeToLiveSeconds will expire anyway and the element will be removed from the cache in which I’ve put it, right?
Yes, you are right.
For example:
timeToIdleSeconds = 30: if the cached object was not requested during that 30 seconds, it expires => last access time countstimeToLiveSeconds = 60: after 60 seconds the cached object will expire – no matter how often it was requested or requested at all => creation time countsFrom the docs (older version 1.4):