0

Assume a Flask application that allows to build an object (server-side) through a number of steps (wizard-like ; client-side). I would like to create an initial object server-side an build it up step by step given the client-side input, keeping the object 'alive' throughout the whole build-process. A unique id will be associated with the creation of each new object / wizard.

Serving the Flask application with the use of WSGI on Apache, requests can go through multiple instance of the Flask application / multiple threads.

How do I keep this object alive server-side, or in other words how to keep some kind of global state? I like to keep the object in memory, not serialize/deserialize it to/from disk. No cookies either.

Edit:

I'm aware of the Flask.g object but since this is on per request basis this is not a valid solution. Perhaps it is possible to use some kind of cache layer, e.g.:

from werkzeug.contrib.cache import SimpleCache
cache = SimpleCache()

Is this a valid solution? Does this layer live across multiple app instances?

narf
  • 1
  • 2

1 Answers1

0

You're looking for sessions.

You said you don't want to use cookies, but did you mean you didn't want to store the data as a cookie or are you avoiding cookies entirely? For the former case, take a look at server side sessions, e.g. Flask-KVSession

Instead of storing data on the client, only a securely generated ID is stored on the client, while the actual session data resides on the server.

Dmiters
  • 2,011
  • 3
  • 23
  • 31