I have a web service on Flask , in which I do caching using the object class SimpleCache . The problem occurs when gunicorn is gunicorn . Each process has its own cache, can I somehow combine the gunicorn process gunicorn ?
- oneThe documentation says that SimpleCache is only for the development server, so do not use it and take, for example, memcached - andreymal
- @andreymal you could arrange your message as an answer. Then I would mark him as the best. he really helped me. - faoxis
1 answer
According to the documentation , SimpleCache intended only for the development server. It uses the most ordinary python dictionary, in which cached objects are stored. From this it is obvious that such a cache does not get out of the process, and gunicorn creates several worker processes, and each one has its own cache dictionary. SimpleCache not intended for such things. (Even if it suddenly seems to someone that this is not very scary, it’s still not necessary: when it becomes necessary to invalidate the cache, it will be very difficult to make it simultaneously in all processes.)
The cache should be moved somewhere outside the gunicorn processes. The same documentation suggests using MemcachedCache . Naturally, you need to remember to install memcached in the system and start it yourself :) All processes will access it alone, and all of them will have a common cache.