[Flask] Is filesystem cache safe between processes?

Skip Montanaro skip.montanaro at gmail.com
Fri Mar 2 11:14:13 EST 2018


> They can. Filesystem can be used concurrently.

Thanks, I spent a bit of time looking at the underlying
werkzeug.contrib.cache code and concluded the same thing. Regarding
writes, when writing a key/value pair to the cache, it uses
tempfile.mkstemp() to write the data. The chance of collisions at that
level should be quite small. Then it calls os.rename() to move the
result into place. That's an atomic operation, so the worst that can
happen is that multiple workers write the same key/value pair, then
overwrite each other's work during the rename. That I can certainly
live with.

Manual inspection of the logs since restart suggests the cache is
performing as intended.

Thx,

Skip


More information about the Flask mailing list