[IMP] base, website: add an api to populate the cache

Part-of: odoo/odoo#119813
This commit is contained in:
Xavier-Do
2023-07-18 11:42:26 +02:00
parent 402e5d0acb
commit 88786dde49
3 changed files with 13 additions and 15 deletions
+8 -2
View File
@@ -59,9 +59,15 @@ class ormcache(object):
self.method = method
self.determine_key()
lookup = decorator(self.lookup, method)
lookup.ormcache = self
lookup.cache = self
return lookup
def add_value(self, *args, cache_value=None, **kwargs):
model = args[0]
d, key0, _ = self.lru(model)
key = key0 + self.key(*args, **kwargs)
d[key] = cache_value
def determine_key(self):
""" Determine the function that computes a cache key from arguments. """
if self.skiparg is None:
@@ -167,7 +173,7 @@ def log_ormcache_stats(sig=None, frame=None):
def get_cache_key_counter(bound_method, *args, **kwargs):
""" Return the cache, key and stat counter for the given call. """
model = bound_method.__self__
ormcache = bound_method.ormcache
ormcache = bound_method.cache
cache, key0, counter = ormcache.lru(model)
key = key0 + ormcache.key(model, *args, **kwargs)
return cache, key, counter