Odoo Help


How are the caches cleaned in multi-process mode (i.e. under Gunicorn)?

Nicolas Bessi
on 2/5/13, 10:23 AM 9,192 views

When developing I use @tools.ormcache() or @tool.ormcache_multi(multi=x) to gain performance. From time to time I need to clean caches. For this I use my_model.clear_caches().

When we are in Gunicorn mode does clean_caches notify all worker to automatically clean their own cache, or do I have to do some other calls? Is there some latency?

This is not really clear or maybe I missed some documentation.

Vo Minh Thu
On 2/5/13, 5:15 PM

Each registry (i.e. the self.pool variable on any model instance) is kept in sync across workers through the database. Two sequences in database are used, one for the caches and one for the registry itself (e.g. to keep track of the fact a module has been installed), and each worker checks those sequences.

Whenever the sequences have a different value than what the worker was assuming, the workers will either clean their caches or reload the registry (thus loading any newly installed module, as it would have been flagged as "installed" in ir.module.module).

The check on the sequences is done right when a new RPC call is done. Sequences are updated at the end of an RPC call. So there is some latency between a cache invalidation on a worker and the corresponding invalidation on another worker. But this is in fact ok: when the signaling occurs, it is itself part of the database transaction associated to the RPC call. Since the check is done right at the beginning of a new RPC call, that call/transaction will see correctly cleaned caches and updated registry.

See Guewen Baconnier's answer for the few places where the logic is implemented.

To have all that signaling occur, the openerp.multi_process symbol must be set to True. This should be set in the configuration file used with Gunicorn or other WSGI servers.

In trunk, the oe web command sets also openerp.multi_process to True so that multiple oe web processes can be run side by side.


Guewen Baconnier - Software Developer, Camptocamp

--Guewen Baconnier - Software Developer, Camptocamp--
| 6 7 8
Lausanne, Switzerland
--Guewen Baconnier - Software Developer, Camptocamp--

Guewen works at Camptocamp as an Odoo developer since 2010. He is the lead developer of the Odoo Connector framework and the Magento Connector. He is a delegate member of the OCA, a committer and an active contributor to the OCA projects.


Guewen Baconnier - Software Developer, Camptocamp
On 2/5/13, 11:43 AM

From what I can read, when clear_caches is called, it sets _any_cache_cleared to true on the pool registry.

This attribute is used to know if a model cache has been cleared so it can be signaled to the other processes (see openerp.modules.registry, methods check_registry_signaling and signal_caches_change).

The check of signaling is done before each RPC request on models (openerp.service.web_services.objects_proxy) or print of a report (openerp.service.web_services.report_spool) and the signaling is done after the request or the print of the report. ir.cron calls the check and signaling itself (openerp.addons.base.ir_cron) too.

The signaling use a sequence in the database: base_cache_signaling. Each time the sequence is increased, it means that the caches have to be cleared.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 2/5/13, 10:23 AM
Seen: 9192 times
Last updated: 3/16/15, 8:10 AM