Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In-memory storage for flask application

Tags:

python

flask

My flask application stores some data in a database. I want this data to be discarded if my application has been down for some time. The reason for this is that I want to be sure that I missed no REST call to my application.

The obvious and efficient solution is storing this data in memory but I am open to any solution (e.g. delete old records on application restart).

like image 990
utapyngo Avatar asked Jun 20 '12 06:06

utapyngo


2 Answers

If you don't need persistence in your application, why don't you use the SQLite backend (easy in flask) and store the database in memory (using the :memory: filename as data base), then on each shutdown your data will be cleaned.

like image 64
Cédric Julien Avatar answered Nov 12 '22 23:11

Cédric Julien


You can use persisted memory-mapped files. Python has a facility (mmap) to work with such files.

like image 36
Sergei Danielian Avatar answered Nov 13 '22 00:11

Sergei Danielian