Clear the CacheRegion

Issue #7 resolved
Mark
created an issue

It would be useful if the CacheRegion had a clean() method, in addition to the delete() method, that would remove all cached values (or at least their keys) from the CacheRegion.

The use-case I have is that I cache search results and occasionally need to clear the whole cache, when an update to the search index has been performed.

Comments (8)

  1. Michael Bayer repo owner

    the problem with this feature is that it can't be implemented for many backends, in particular memcached, the most common backend. memcached has no way to offer a listing of keys currently cached.

  2. Michael Bayer repo owner

    Ah but, in beaker what we did do was give the cache region a so-called "start" time. That is, when the region pulls a cached value, it not only checks the creation time of the value against the current time - expiration time, it also checks that the creation time is greater than the "start" time, which would typically be set to the timestamp at region creation time. So this doesn't clear anything out but has the effect of considering everything in the cache before region startup time to be invalid.

    Mind if I update the title here to match that description ? because dogpile.cache does need this feature (I used to use it all the time).

  3. Mark reporter

    Ah, right. Difficult. Is there a way to access the underlying backend from a CacheRegion? That would make it possible to get the keys, where this is supported by the backend.

  4. Mark reporter

    So in that case, by setting the "start" time to the current time, everything created previously would become invalid? That sounds like a nice solution.

  5. Mark reporter

    I've been continuously running the updated version for about 3 weeks now and have seen no errors or strange behaviour from the change. As far as I am concerned, it looks stable.

  6. Log in to comment