I followed a tutorial of Flask-Cache and tried to implement it myself. Given the following example, why would Flask not cache the time?
from flask import Flask
import time
app = Flask(__name__)
cache = Cache(config={'CACHE_TYPE': 'simple'})
cache.init_app(app)
@app.route('/time')
@cache.cached(timeout=50, key_prefix='test')
def test():
return time.ctime()
Output is always the current time.
It seems like the cache is recreated every single request. What am I doing wrong?
Edit: I execute the following python-file with Python 2.7.6:
def runserver():
port = int(os.environ.get('PORT', 5000))
Triangle(app)
app.run(host='0.0.0.0', port=port, processes=5)
if __name__ == '__main__':
runserver()
app.run()
development server, the time is cached. How are you running this? – BoutteSimpleCache
is a global dictionary. If you are using a WSGI server that uses multiprocessing to scale out, you'll get separate copies and they'll appear not to cache. – Boutte