문제

suppose I have the following snippet which caches the function load using search_term, limit as key, presumably.(In beaker it's converted to string representation of tuple of all arguments I suppose)

# Assuming a cache object is available like:
cache = CacheManager(dict_of_config_options)


def populate_things():

    @cache.cache('mycache', expire=15)
    def load(search_term, limit, offset):
        return load_the_data(search_term, limit, offset)

    return load('rabbits', 20, 0)

Now if I do some insertion into the database and want to invalidate all cached data associated with the newly updated search_term, how can I enumerate all cached data so I can manually invalidate them?

도움이 되었습니까?

해결책

Invalidating a single key is straight-forward:

cache.get_cache("mycache").remove_value(key="rabbits")

If there's, as your question's title says, whole bunch of keys that need to be invalidated, I'd recommend to put them in separate cache and then clearing the whole cache:

cache.get_cache("all_my_rabbit_stuff").clear()

You'll need some careful planning what goes in which cache so that

  • you don't end up with millions of small caches
  • when wiping out a cache, you don't throw away some still-fresh data too
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top