how to use flask-cache and memcached?

心不动则不痛 提交于 2019-12-06 09:45:04

问题


an example for flask-cache with type "simple" below but how can i use flask-cache with memcache ? I need ur help thank you :)

from flask import Flask
import random

# import the flask extension
from flask.ext.cache import Cache

app = Flask(__name__)

#import config setting
app.config["CACHE_TYPE"]="simple"

# register the cache instance and binds it on to your app 
app.cache = Cache(app)

@app.route("/")
@app.cache.cached(timeout=50,key_prefix="hello")  # cache this view for 30 seconds
def cached_view():
    a=random.randint(0,100)
    return str(a)

if __name__ == "__main__":
    app.run(port=5000, debug=True, host='0.0.0.0')

回答1:


:) I have solved this problem

Q:How to use memcached with flask-cache

A: just modify the cache type from "simple" to "memcached",so easy

attention:

the most important thing you should notice is that you should install libmemcached, pylibmc and python-dev. Also, the most important is that the version of libmemcached should match the version of pylibmc,otherwise it would be wrong when pip install pylibmc



来源:https://stackoverflow.com/questions/25176813/how-to-use-flask-cache-and-memcached

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!