[IMP] registry: multiple ormcache
One of the main issue with ormcache is that the invalidation clears everything, meaning that some value, slow to compute but with a long lifetime, can be removed from the cache because an easy to invalidate value is cleared, like after writting or creating a product has an example. Most example in the code will try to invalidate the cache of the models doing something like `env['ir.qweb'].clear_caches()` but it is finally equivalent to `env.registry.clear_cache()`, and cross worker. The idea is to have multiple cache, maybe with specific sizes for a specific purpose. Having one per model is maybe a bad idea because it will be difficult to size the LRU correcly, and it is too dynamic. Checking invalidation may be expensive. The proposed solution is closed allow a limited number of named caches, using onse sequence per cache. This is actually close to the cache_longterm. We want to discourage using a specific cache for one use case in the buisness code. Adding a cache shouldn't be something easy, doable in stable. Note that we could also change the invalisation mecanism using an insert only table. We an check the sequence of this table, but also fetch all invalidation messages. Another possible improvement, especially if we have more than x cache is to have a global sequence, checking signaling would mean to check the main sequence, and only the other ones if the main one changed. Note that this poc is inspired from the long term cache but not all use case where applie yet. Part-of: odoo/odoo#119813
This commit is contained in:
@@ -749,10 +749,11 @@ class TransactionCase(BaseCase):
|
||||
if (cls.registry_start_sequence != cls.registry.registry_sequence) or cls.registry.registry_invalidated:
|
||||
with cls.registry.cursor() as cr:
|
||||
cls.registry.setup_models(cr)
|
||||
cls.registry.registry_invalidated = False
|
||||
cls.registry.registry_invalidated = False
|
||||
cls.registry.clear_all_caches()
|
||||
cls.registry.cache_invalidated.clear()
|
||||
|
||||
cls.addClassCleanup(reset_changes)
|
||||
cls.addClassCleanup(cls.registry.clear_caches)
|
||||
|
||||
cls.cr = cls.registry.cursor()
|
||||
cls.addClassCleanup(cls.cr.close)
|
||||
@@ -771,7 +772,7 @@ class TransactionCase(BaseCase):
|
||||
self.addCleanup(envs.update, list(envs))
|
||||
self.addCleanup(envs.clear)
|
||||
|
||||
self.addCleanup(self.registry.clear_caches)
|
||||
self.addCleanup(self.registry.clear_all_caches)
|
||||
|
||||
# This prevents precommit functions and data from piling up
|
||||
# until cr.flush is called in 'assertRaises' clauses
|
||||
@@ -810,7 +811,7 @@ class SingleTransactionCase(BaseCase):
|
||||
super().setUpClass()
|
||||
cls.registry = odoo.registry(get_db_name())
|
||||
cls.addClassCleanup(cls.registry.reset_changes)
|
||||
cls.addClassCleanup(cls.registry.clear_caches)
|
||||
cls.addClassCleanup(cls.registry.clear_all_caches)
|
||||
|
||||
cls.cr = cls.registry.cursor()
|
||||
cls.addClassCleanup(cls.cr.close)
|
||||
|
||||
Reference in New Issue
Block a user