7

I am using Flask cache in my API in python.

Currently I am using the decorator @app.cache.memoize(cache_memoize_value) and I flush it by calling app.cache.delete_memoized(view)

The problem is that with memoize it will be cached for n views and not for a specific amount of time. If I want to specify a timeout for the cache I need to use the decorator @app.cache.cached(timeout=300) and clear it with app.cache.clear(). However, this clear method will clear everything and not only a specific view.

How can I only clear a specific view while using the cached decorator?

4

2 回答 2

11
  • 对于cache.cached(),用于cache.delete()删除特定缓存,传递缓存键(默认为view/<request.path>)。
  • 对于cache.memoize(), 用于cache.delete_memoized()删除特定缓存,传递缓存键(默认为带或不带 args 的函数名)。
  • 用于cache.clear()删除所有缓存数据。
于 2018-04-29T03:28:15.470 回答
3

这实际上很容易,我之前应该尝试过。与缓存装饰器一样,您可以在记忆化装饰器中指定一个值。但不是这样做: @app.cache.memoize(cache_memoize_value)

你需要这样做 @app.cache.memoize(timeout=cache_memoize_value)

于 2016-03-30T13:02:22.130 回答