File: cache.rst

package info (click to toggle)
tryton-server 5.0.4-2%2Bdeb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 5,932 kB
  • sloc: python: 35,777; xml: 4,452; sh: 300; sql: 230; makefile: 88
file content (57 lines) | stat: -rw-r--r-- 1,588 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
.. _ref-cache:
.. module:: trytond.cache

=====
Cache
=====

.. class:: Cache(name[, size_limit[, context]])

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` field can
be used to limit the number of values cached and the `context` parameter
is used to indicate if the cache depends on the user context and is true
by default.
The cache is cleaned on :class:`Transaction` starts and resets on
:class:`Transaction` commit 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.
..

.. 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`.

.. method:: set(key, value)

Sets the `value` of the `key` in the cache.

.. method:: clear()

Clears all the keys in the cache.

.. staticmethod:: clean(dbname)

Clean the cache for database `dbname`

.. staticmethod:: reset(dbname, name)

Reset the `name` cache for database `dbname`

.. staticmethod:: resets(dbname)

Resets all the caches stored for database `dbname`

.. staticmethod:: drop(dbname)

Drops all the caches for database `dbname`

.. 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.
..