From 421ec76c4908090d530698c1f1660e5b48ff35ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 13 Jan 2021 00:26:53 +0100 Subject: [PATCH] Clear all cache after module loaded As we rollback the cache modification when loading a module, we must clear all of them at the end to ensure to not keep outdated data. issue9759 review339421002 --- CHANGELOG | 1 + doc/ref/cache.rst | 4 ++++ trytond/cache.py | 5 +++++ trytond/modules/__init__.py | 3 +++ 4 files changed, 13 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index fd5066e8de..0ac3237dce 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Add clear_all method to Cache * Support Genshi element directives in HTML editor * Add firstline tool * Add support for Python 3.9 diff --git a/doc/ref/cache.rst b/doc/ref/cache.rst index b4da3cb700..12bd659b7f 100644 --- a/doc/ref/cache.rst +++ b/doc/ref/cache.rst @@ -35,6 +35,10 @@ Sets the ``value`` of the ``key`` in the cache. Clears all the keys in the cache. +.. classmethod:: clear_all() + +Clears all cache instances. + .. classmethod:: sync(transaction) Synchronize cache instances using transaction. diff --git a/trytond/cache.py b/trytond/cache.py index 489454fd88..96107a97fd 100644 --- a/trytond/cache.py +++ b/trytond/cache.py @@ -75,6 +75,11 @@ class BaseCache(object): def clear(self): raise NotImplementedError + @classmethod + def clear_all(cls): + for inst in cls._instances.values(): + inst.clear() + @classmethod def sync(cls, transaction): raise NotImplementedError diff --git a/trytond/modules/__init__.py b/trytond/modules/__init__.py index 2493a6fc3c..6fad3d12d5 100644 --- a/trytond/modules/__init__.py +++ b/trytond/modules/__init__.py @@ -299,6 +299,9 @@ def load_module_graph(graph, pool, update=None, lang=None): while modules_todo: (module, to_delete) = modules_todo.pop() convert.post_import(pool, module, to_delete) + + # Ensure cache is clear for other instances + Cache.clear_all() logger.info('all modules loaded')