File: grn_cache.rst

package info (click to toggle)
groonga 9.0.0-1%2Bdeb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 101,496 kB
  • sloc: ansic: 608,707; ruby: 35,042; xml: 23,643; cpp: 10,319; sh: 7,453; yacc: 5,968; python: 3,033; makefile: 2,609; perl: 133
file content (114 lines) | stat: -rw-r--r-- 3,551 bytes parent folder | download | duplicates (5)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
.. -*- rst -*-

.. highlightlang:: c

``grn_cache``
=============

Summary
-------

.. note::

   This API is experimental.

``grn_cache`` is a data store that keeps responses of
:doc:`/reference/commands/select` command. It is not general use cache
object. It is only for :doc:`/reference/commands/select` command.

You can just change the current cache object by
:c:func:`grn_cache_current_set()`. :doc:`/reference/commands/select`
command response cache is done internally.

:doc:`/reference/commands/select` command uses one global cache
object. If you open multiple databases, the one cache is shared. It is
an important problem.

If you open multiple databases and use
:doc:`/reference/commands/select` command, you need to use
``grn_cache`` object. It is :doc:`/reference/executables/groonga-httpd`
case. If you open only one database or don't use
:doc:`/reference/commands/select` command, you don't need to use
``grn_cache`` object. It is `rroonga
<http://ranguba.org/#about-rroonga>`_ case.

Example
-------

Here is an example that change the current cache object.

.. code-block:: c

   grn_cache *cache;
   grn_cache *cache_previous;
   cache = grn_cache_open(ctx);
   cache_previous = grn_cache_current_get(ctx);
   grn_cache_current_set(ctx, cache);
   /* grn_ctx_send(ctx, ...); */
   grn_cache_current_set(ctx, cache_previous);


Reference
---------

.. c:type:: grn_cache

   It is an opaque cache object. You can create a ``grn_cache`` by
   :c:func:`grn_cache_open()` and free the created object by
   :c:func:`grn_cache_close()`.

.. c:function:: grn_cache *grn_cache_open(grn_ctx *ctx)

   Creates a new cache object.

   If memory allocation for the new cache object is failed, ``NULL``
   is returned. Error information is stored into the ``ctx``.

   :param ctx: The context.
   :return: A newly allocated cache object on success, ``NULL``
            otherwise. The returned cache object must be freed by
            :c:func:`grn_cache_close()`.

.. c:function:: grn_rc grn_cache_close(grn_ctx *ctx, grn_cache *cache)

   Frees resourses of the ``cache``.

   :param ctx: The context.
   :param cache: The cache object to be freed.
   :return: ``GRN_SUCCESS`` on success, not ``GRN_SUCCESS`` otherwise.

.. c:function:: grn_rc grn_cache_current_set(grn_ctx *ctx, grn_cache *cache)

   Sets the cache object that is used in
   :doc:`/reference/commands/select` command.

   :param ctx: The context.
   :param cache: The cache object that is used in
                 :doc:`/reference/commands/select` command.
   :return: ``GRN_SUCCESS`` on success, not ``GRN_SUCCESS`` otherwise.

.. c:function:: grn_cache *grn_cache_current_get(grn_ctx *ctx)

   Gets the cache object that is used in
   :doc:`/reference/commands/select` command.

   :param ctx: The context.
   :return: The cache object that is used in
            :doc:`/reference/commands/select` command. It may be ``NULL``.

.. c:function:: grn_rc grn_cache_set_max_n_entries(grn_ctx *ctx, grn_cache *cache, unsigned int n)

   Sets the max number of entries of the cache object.

   :param ctx: The context.
   :param cache: The cache object to be changed.
   :param n: The new max number of entries of the cache object.
   :return: ``GRN_SUCCESS`` on success, not ``GRN_SUCCESS`` otherwise.

.. c:function:: unsigned int grn_cache_get_max_n_entries(grn_ctx *ctx, grn_cache *cache)

   Gets the max number of entries of the cache object.

   :param ctx: The context.
   :param cache: The target cache object.
   :return: The max number of entries of the cache object.