Cache#
- class trytond.cache.Cache(name[, duration[, context[, context_ignored_keys]]])#
Use to cache values between server requests.
The
nameshould be unique and it’s used to identify the cache. Usually<class_name>.<content_name>is used to make it unique.The
durationparameter defines how long a cached value stays valid but if it is not set the value remains valid until it is cleared.And the
contextparameter is used to indicate if the cache depends on the user context and isTrueby default. Keys specified incontext_ignored_keysare ignored.The cache is cleaned on
Transactionstarts and resets onTransactioncommit or rollback.Warning
As there is no deepcopy of the values cached, they must never be mutated after being set in or retrieved from the cache.
- Cache.size_limit#
The maximal number of values cached. The value comes from the entry with the same
nameunder the cache section of the configuration using thedefaultentry as default value.
- Cache.hit#
Count the number of times the cache returned a cached value.
- Cache.miss#
Count the number of times the cache did not contain the key.
- classmethod Cache.stats()#
Yield statistics for each instance.
- Cache.get(key[, default])#
Retrieve the value of the key in the cache.
If a
defaultis specified it is returned when the key is missing otherwise it returnsNone.
- Cache.set(key, value)#
Set the
valueof thekeyin the cache.
- Cache.clear()#
Clear all the keys in the cache.
- classmethod Cache.clear_all()#
Clear all cache instances.
- classmethod Cache.sync(transaction)#
Synchronize caches between servers using
transactioninstance.
- Cache.sync_since(value)#
Return
Trueif the last synchronization was done beforevalue.
- classmethod Cache.commit(transaction)#
Apply cache changes from transaction.
- classmethod Cache.rollback(transaction)#
Remove cache changes from transaction.
- classmethod Cache.drop(dbname)#
Drop all caches for named database.
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
class of the cache section.