Answer the question
In order to leave comments, you need to log in
Flask caching not working, what should I do?
Good afternoon, the problem is that when I save a variable in the cache, and try to get it, the site says that there is nothing in the cache for my request.
Here is the code:
from flask import Flask
from werkzeug.contrib.cache import MemcachedCache
app = Flask(__name__)
cache = MemcachedCache(['localhost:11211'])
@app.route('/test')
def test():
hw = 'Hello World!'
cache.set('f', hw, timeout = None)
get = cache.get('f')
return render_template('pages/test.html', get=get)
if __name__ == '__main__':
app.run()
Cachelib
.
Answer the question
In order to leave comments, you need to log in
https://pythonhosted.org/Flask-Caching/
Try this module
from flask_caching import Cache
cache = Cache(app, config={'CACHE_TYPE': 'memcached',
"CACHE_MEMCACHED_SERVERS": ['127.0.0.1:11211']})
cache.set('f', "aaaa")
cache.get('f')
Thanks, problem solved, I just forgot to install memcache server
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question