diff --git a/trytond/CHANGELOG b/trytond/CHANGELOG index 26e2e0aa21..1bd4302e0b 100644 --- a/trytond/CHANGELOG +++ b/trytond/CHANGELOG @@ -1,3 +1,4 @@ +* Allow cache size to be configured * Add local and global list of ignore context keys * Add functions in transaction for check access and active record * Add check_access and active_records attribute to Transaction diff --git a/trytond/doc/ref/cache.rst b/trytond/doc/ref/cache.rst index 076cae3628..e7e354d961 100644 --- a/trytond/doc/ref/cache.rst +++ b/trytond/doc/ref/cache.rst @@ -4,16 +4,13 @@ Cache ===== -.. class:: Cache(name[, size_limit[, duration[, context[, context_ignored_keys]]]]) +.. class:: Cache(name[, duration[, context[, context_ignored_keys]]]) Use to cache values between server requests. The ``name`` should be unique and it's used to identify the cache. Usually ``.`` is used to make it unique. - The ``size_limit`` parameter can be used to limit the number of values - cached and it has ``1024`` as the default value. - The ``duration`` parameter defines how long a cached value stays valid but if it is not set the value remains valid until it is cleared. @@ -29,6 +26,13 @@ Cache As there is no deepcopy of the values cached, they must never be mutated after being set in or retrieved from the cache. +.. attribute:: Cache.size_limit + + The maximal number of values cached. + The value comes from the entry with the same ``name`` under the ``cache`` + section of the :ref:`configuration ` using the + ``default`` entry as default value. + .. attribute:: Cache.hit Count the number of times the cache returned a cached value. diff --git a/trytond/doc/topics/configuration.rst b/trytond/doc/topics/configuration.rst index 9a0bd00d98..68fb138d01 100644 --- a/trytond/doc/topics/configuration.rst +++ b/trytond/doc/topics/configuration.rst @@ -304,6 +304,13 @@ The number of field to load with an ``eager`` :attr:`Field.loading Default: ``100`` +default +~~~~~~~ + +The default :attr:`~trytond.cache.Cache.size_limit` of :class:`~trytond.cache.Cache`. + +Default: ``1024`` + clean_timeout ~~~~~~~~~~~~~ diff --git a/trytond/trytond/cache.py b/trytond/trytond/cache.py index 4a4ec71a3c..48c4a59a3d 100644 --- a/trytond/trytond/cache.py +++ b/trytond/trytond/cache.py @@ -22,6 +22,7 @@ from trytond.transaction import Transaction __all__ = ['BaseCache', 'Cache', 'LRUDict', 'LRUDictTransaction'] _clear_timeout = config.getint('cache', 'clean_timeout', default=5 * 60) +_default_size_limit = config.getint('cache', 'default') logger = logging.getLogger(__name__) @@ -69,14 +70,15 @@ class BaseCache(object): } def __init__( - self, name, size_limit=1024, duration=None, context=True, + self, name, duration=None, context=True, context_ignored_keys=None): assert ((context_ignored_keys is not None and context) or (context_ignored_keys is None)), ( f"context_ignored_keys ({context_ignored_keys}) is not valid" f" in regards to context ({context}).") self._name = name - self.size_limit = size_limit + self.size_limit = config.getint( + 'cache', name, default=_default_size_limit) self.context = context self.context_ignored_keys = set() if context and context_ignored_keys: diff --git a/trytond/trytond/config.py b/trytond/trytond/config.py index bbf13e41f9..0b2a06d9ca 100644 --- a/trytond/trytond/config.py +++ b/trytond/trytond/config.py @@ -74,6 +74,9 @@ class TrytonConfigParser(configparser.ConfigParser): self.set('cache', 'model', '200') self.set('cache', 'record', '2000') self.set('cache', 'field', '100') + self.set('cache', 'default', '1024') + self.set('cache', 'ir.message', '10240') + self.set('cache', 'ir.translation', '10240') self.add_section('queue') self.set('queue', 'worker', 'False') self.add_section('ssl') diff --git a/trytond/trytond/ir/message.py b/trytond/trytond/ir/message.py index f3825d251d..deb7217492 100644 --- a/trytond/trytond/ir/message.py +++ b/trytond/trytond/ir/message.py @@ -11,7 +11,7 @@ class Message(ModelSQL, ModelView): "Message" __name__ = "ir.message" - _message_cache = Cache('ir.message', size_limit=10240, context=False) + _message_cache = Cache('ir.message', context=False) text = fields.Text("Text", required=True, translate=True) @classmethod diff --git a/trytond/trytond/ir/translation.py b/trytond/trytond/ir/translation.py index 8276910fa5..8b84047a1f 100644 --- a/trytond/trytond/ir/translation.py +++ b/trytond/trytond/ir/translation.py @@ -71,8 +71,7 @@ class Translation(ModelSQL, ModelView): model = fields.Function(fields.Char('Model'), 'get_model', searcher='search_model') overriding_module = fields.Char('Overriding Module', readonly=True) - _translation_cache = Cache('ir.translation', size_limit=10240, - context=False) + _translation_cache = Cache('ir.translation', context=False) _translation_report_cache = Cache( 'ir.translation.get_report', context=False) _get_language_cache = Cache('ir.translation.get_language', context=False)