Files
tryton/doc/ref/cache.rst
T

66 lines
1.9 KiB
ReStructuredText
Raw Normal View History

2016-10-26 15:55:05 +02:00
.. _ref-cache:
.. module:: trytond.cache
=====
Cache
=====
2019-04-11 18:35:25 +02:00
.. class:: Cache(name[, size_limit[, duration[, context]]])
2016-10-26 15:55:05 +02:00
The class is used to cache values between server requests. The ``name`` should
be unique and it's used to identify the cache. We usually use
``<class_name>.<content_name>`` 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
2019-04-11 18:35:25 +02:00
but if it is not set the value remains valid until it is cleared. And the
``context`` parameter is used to indicate if the cache depends on the user
2019-04-11 18:35:25 +02:00
context and is true by default. The cache is cleaned on :class:`Transaction`
starts and resets on :class:`Transaction` commit or rollback.
2016-10-26 15:55:05 +02:00
2017-01-19 22:57:09 +01:00
.. warning::
As there is no deepcopy of the values cached, they must never be mutated
after being set in or retrieved from the cache.
..
2016-10-26 15:55:05 +02:00
.. method:: get(key[, default])
Retrieve the value of the key in the cache. If a ``default`` is specified it
will be returned when the key is missing otherwise it will return ``None``.
2016-10-26 15:55:05 +02:00
.. method:: set(key, value)
Sets the ``value`` of the ``key`` in the cache.
2016-10-26 15:55:05 +02:00
.. method:: clear()
Clears all the keys in the cache.
2021-01-13 00:26:53 +01:00
.. classmethod:: clear_all()
Clears all cache instances.
2019-01-18 11:57:11 +01:00
.. classmethod:: sync(transaction)
2016-10-26 15:55:05 +02:00
2019-01-18 11:57:11 +01:00
Synchronize cache instances using transaction.
2016-10-26 15:55:05 +02:00
.. method:: sync_since(value)
Return ``True`` if the last synchronization was done before ``value``.
2019-01-18 11:57:11 +01:00
.. classmethod:: commit(transaction)
2016-10-26 15:55:05 +02:00
2019-01-18 11:57:11 +01:00
Apply cache changes from transaction.
2016-10-26 15:55:05 +02:00
2019-01-18 11:57:11 +01:00
.. classmethod:: rollback(transaction)
2016-10-26 15:55:05 +02:00
2019-01-18 11:57:11 +01:00
Remove cache changes from transaction.
2016-10-26 15:55:05 +02:00
2020-12-26 21:49:29 +01:00
.. classmethod:: drop(dbname)
2016-10-26 15:55:05 +02:00
Drops all the caches for database ``dbname``
2016-10-26 15:55:05 +02:00
.. note::
By default Tryton uses a MemoryCache, but this behaviour can be overridden
by setting a fully qualified name of an alternative class defined in the
configuration ``class`` of the ``cache`` section.
2016-10-26 15:55:05 +02:00
..