Use channel to synchronize cache

Rational

We synchronize the cache on each request (and we even tried to reduce the number) but this is a little expensive knowing that such cache should be almost static. Also the commit part needs to search and update/insert row in a table and this may create conflicts.

Proposal

Following the Bus design, we could have a thread daemon listening on a channel (if the database support it). The message passed to this channel is the name of the cache to clear.
In order to prevent thread started before the clearing to fill the cache with outdated data, we need to order the transaction using a monotonic timestamp which is compared to the last clearing of the Cache instance.
As this will create a database connection per process and database, this should be optional by configuration.

Implementation

https://bugs.tryton.org/issue8019
https://bugs.tryton.org/issue8027

The patches are ready for testing. I used a clear timeout of zero to activate the channel.
I just found during debugging that two listener thread will be launch in development mode. This is because the werkzeug simple server launch two processes when the reloader is activated. A first thread is launched when the transaction to determine the modules to load is executed and this is before the werkzeug start the new process. I do not think it is a problem.

This topic was automatically closed after 14 days. New replies are no longer allowed.