I'm looking for the best way to keep big objects in memory in a flask application, such that I can access it (read-only) inside every request without storing it on disk or in any database. These objects are not serializable since they are complex instances of classes from imported libraries (then an in-RAM database is not an option). My major problem is that flask uses multiple processes, so defining a global variable may result in several copies of the same objects (which I want to avoid). My main idea to tackle this is the following:
- when the flask application is started, I create a unique subprocess which will load the data from disk and keep it in the RAM (as regular python objects).
- inside a request, I get the data by communicating with the subprocess.
Do you know a library that already does this ? Do you have a better idea to access these data as fast as possible ?