a.m*_*.m. 11 python caching flask flask-extensions flask-cache
我在使用Flask-Cache时遇到了问题.我需要在需要的基础上进行缓存,方法是定义一个配置变量,用户可以设置该变量来启用或禁用缓存.
我正在使用Flask-Cache进行缓存
cache = Cache(config = {'CACHE_TYPE':'redis'})
app = Flask(名字)
初始化缓存
cache.init_app(APP)
清除缓存
使用app.app_context():
Run Code Online (Sandbox Code Playgroud)cache.clear()
并使用缓存(在views.py中)作为
@ app.route('/',methods = ['GET'])
@validate_access(current_user,"read")
@要求登录
@ cache.memoize()
def get_values(id):
Run Code Online (Sandbox Code Playgroud)return get_values()
在使用Flask-Cache时,我没有获得正确的启用/禁用缓存的方法.是否有一种标准方式可以完全启用/禁用缓存行为.
Sea*_*ira 13
在初始化Flask-Cache之前,只需将app.config的CACHE_TYPE键设置为"null":
app.config["CACHE_TYPE"] = "null"
# change to "redis" and restart to cache again
# some time later
cache.init_app(app)
# All caching functions will simply call through
# to the wrapped function, with no caching
# (since NullCache does not cache).
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15012 次 |
| 最近记录: |