Allow cache size to be configured

Closes #11383
This commit is contained in:
Cédric Krier committed 2023-01-14 20:11:32 +01:00
1 parent ad5ed8cb5f
commit fd3ea318a8
7 files changed
+25 -9

No files matched your search

+1
View File
@@ -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
+8 -4
View File
@@ -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 ``<class_name>.<content_name>`` 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 <topics-configuration>` using the
``default`` entry as default value.
.. attribute:: Cache.hit
Count the number of times the cache returned a cached value.
+7
View File
@@ -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
~~~~~~~~~~~~~
+4 -2
View File
@@ -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:
+3
View File
@@ -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')
+1 -1
View File
@@ -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
+1 -2
View File
@@ -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)