0

We decide to use cache (not decide specific cache) , but today came to know that we need to invalidate the cache data or refresh the cache data for every 2 minutes by connecting to datastore , but i am thinking that 2 min is not feasible , because if you keep on refresh the cache data for every 2 min , then it is better to connect to the data store itself , so can anyone please suggest what is feasible time interval , we can set to invalidate the cache of old date and refresh the cache with data from data store ?

Note : we are using spring boot , postgres

Bravo
  • 8,589
  • 14
  • 48
  • 85

1 Answers1

1

I think you are a bit confused about caching. If you cache the result of an operation (let say X) for two minutes, it means that everyone that repeat the operation in less than two minutes will have X as result, after the two minutes the cache is invalidated, and will be stored again the next time the operation is requested, so if nobody execute the operation for two hours it will be refreshed after two hours.

The time an item should be present in a cache depends on a lot of factors, there is no way to calculate an absolute feasible value for all cases.

  • Which is the execution rate of the operation to cache?
  • Does the result of the operation change fast? Are you caching something that change daily? hourly?
  • Is it acceptable for who get the cached result to have an old version of the result, how old it can be?

I leave you with this quote (it is a must on this topic):

"There are only two hard problems in Computer Science: 
cache invalidation and naming things."

-- Phil Karlton
rascio
  • 8,968
  • 19
  • 68
  • 108