Flask-Cache是flask一个缓存扩展,可用使用simple、redis、memcache等缓存视图及其他,文档:http://www.pythondoc.com/flask-cache/index.html

在使用Flask-Cache时,采用redis做后端,遇到的问题:

Traceback (most recent call last):
  File "main.py", line 28, in <module>
    cache.init_app(app)
  File "/usr/lib/python2.7/site-packages/flask_cache/__init__.py", line 161, in init_app
    self._set_cache(app, config)
  File "/usr/lib/python2.7/site-packages/flask_cache/__init__.py", line 172, in _set_cache
    import_me))
ImportError: redis is not a valid FlaskCache backend

其实是因为采用redis做后端缓存需要redis python模块,pip install redis,OK!

也可以查看flask-cache仓库的issue: https://github.com/thadeusb/flask-cache/issues/126

·End·