如何使烧杯/塔式缓存中具有公共前缀的多个键失效?
假设我有以下片段,它使用 search_term 缓存函数加载,大概是 limit 作为键。(在烧杯中,它被转换为我想的所有参数元组的字符串表示形式)
# 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)
现在,如果我在数据库中进行一些插入并希望使所有内容无效与新更新的 search_term 关联的缓存数据,如何枚举所有缓存数据以便手动使它们失效?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使单个密钥无效是直接的:
如果正如您的问题标题所述,需要使整堆密钥无效,我建议将它们放在单独的缓存中,然后清除整个缓存:
您将需要一些仔细规划哪个缓存中的内容,这样
Invalidating a single key is straight-forward:
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:
You'll need some careful planning what goes in which cache so that