Issue #37 new
created an issue

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.

Comments (4)

  1. lxyu

    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.

  2. s reporter

    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.

  3. Michael Bayer repo owner

    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.

  4. Log in to comment