Rectangle 27 0

python How to pass complex objects across view functionssessions in Flask?


The only way to get around that is to use an out-of-process store (either a cache on the parent process or a separate Python process that acts as a cache server or some persistence store [Redis, PostGres, etc.])

You can use Flask-Cache (flask.ext.cache)'s SimpleCache (which is really werkzeug.contrib.cache.SimpleCache) to store the data in-memory in your application. The only issue is that you will have one instance of the cache per server process (if you are behind uwsgi, or running on mod_wsgi you will most likely have more than one process handling requests). So it is possible for a user to hit one endpoint of your application, pay the price to fetch the data, and then on the next request, hit a different process and have to pay that cost again (because while Process A has the data cached, Process B does not).

Note