Repository navigation
Expose cache age #37
Description
Activity
lxyu (lxyu) wrote:
I have got similar problems as well, that I want to make a cache expire but still want the cache to be there while I'm updating it.
So I suggest you to take a look at the refresh meth, it can update the cache while others still using the old cache. If you don't have heavy concurrent issue, the current refresh implementation works very well.
lxyu (lxyu) wrote:
FYI, in my case, it's a server-client model which forbid me to use async_creator, but maybe you can use it, it also works.
s (sontek) wrote:
My problem is I don't want to regenerate the cache even if its stale. The operation is extremely heavy and the amount of traffic we get could be regenerating it all the time, so we want to allow the cache to be stale for up to 5 minutes but we need to be able to check how long it has been in cache.
Michael Bayer (zzzeek) wrote:
I think a simple flag "raw=True" on Region.get()/get_or_create(), and then we just make sure to return "value" instead of "value.payload" for both, should be simple.
Here is a draft of a PR adding a
get_age(key)toCacheRegion, WDYT?
#247I have the same need to get the age of a value in the cache, in order to be able to fill an
Ageheader.
I find it cleaner to expose a method to get the age of a value rather than exposing the "private" metadata.Grégoire Deveaux has proposed a fix for this issue in the main branch:
add method to get the CachedValue / cached time directly https://gerrit.sqlalchemy.org/c/sqlalchemy/dogpile.cache/+/5029
I made a change to the PR to just use
CachedValuefor the API. This is already public.- added a commit that references this issue
on Jun 27, 2024
Migrated issue, originally created by s (sontek)
Currently dogpile.cache has the created time stored in metadata in the cache, inside value.metadata["ct"] but doesn't expose this anywhere.
We have some very heavy operations and even if the cache gets invalidated, we want to let it stay stale for up to 5 minutes afterwards during high traffic but we need to pull be able to decide when to regenerate the cache based on the size of the survey.
For example,
If we have a survey that has only 10 respondents, we want to invalidate the cache every time a new respondent comes in.
If a survey has 500 respondents or more, even while new respondents are filling out the survey, we would like to leave the cache in place for up to 5 minutes before we regenerate it.
I would be happy with a get_with_metadata and get_or_create_with_metadata, that way after the call I could inspect the age of the cache from metadata['ct'] and decide if I should invalidate it.