Merge lp:~tangent-org/libmemcached/1.0-build/ Build: jenkins-Libmemcached-187
[m6w6/libmemcached] / docs / memcached_callback.rst
1 =================
2 Setting callbacks
3 =================
4
5
6 Get and set a callback
7
8 .. index:: object: memcached_st
9
10
11 --------
12 SYNOPSIS
13 --------
14
15 #include <libmemcached/memcached.h>
16
17 .. c:type:: memcached_callback_t
18
19 .. c:function:: memcached_return_t memcached_callback_set (memcached_st *ptr, memcached_callback_t flag, const void *data)
20
21 .. c:function:: void * memcached_callback_get (memcached_st *ptr, memcached_callback_t flag, memcached_return_t *error)
22
23 Compile and link with -lmemcached
24
25
26 -----------
27 DESCRIPTION
28 -----------
29
30
31 libmemcached(3) can have callbacks set key execution points. These either
32 provide function calls at points in the code, or return pointers to
33 structures for particular usages.
34
35 :c:func:`memcached_callback_get` takes a callback flag and returns the
36 structure or function set by :c:func:`memcached_callback_set`.
37
38 :c:func:`memcached_callback_set` changes the function/structure assigned by a
39 callback flag. No connections are reset.
40
41 You can use :c:type:`MEMCACHED_CALLBACK_USER_DATA` to provide custom context
42 if required for any of the callbacks.
43
44
45 .. c:type:: MEMCACHED_CALLBACK_CLEANUP_FUNCTION
46
47 When :c:func:`memcached_delete` is called this function will be excuted. At
48 the point of its execution all connections are closed.
49
50
51
52 .. c:type:: MEMCACHED_CALLBACK_CLONE_FUNCTION
53
54 When :c:func:`memcached_delete` is called this function will be excuted.
55 At the point of its execution all connections are closed.
56
57 .. c:type:: MEMCACHED_CALLBACK_PREFIX_KEY
58
59 See :c:type:`MEMCACHED_CALLBACK_NAMESPACE`
60
61 .. c:type:: MEMCACHED_CALLBACK_NAMESPACE
62
63 You can set a value which will be used to create a domain for your keys.
64 The value specified here will be prefixed to each of your keys. The value can
65 not be greater then :c:macro:`MEMCACHED_PREFIX_KEY_MAX_SIZE` - 1 and will
66 reduce :c:macro:`MEMCACHED_MAX_KEY` by the value of your key.
67
68 The prefix key is only applied to the primary key, not the master key.
69 :c:type:`MEMCACHED_FAILURE` will be returned if no key is set. In the case of
70 a key which is too long, :c:type:`MEMCACHED_BAD_KEY_PROVIDED` will be returned.
71
72 If you set a value with the value being NULL then the prefix key is disabled.
73
74 .. c:type:: MEMCACHED_CALLBACK_USER_DATA
75
76 This allows you to store a pointer to a specifc piece of data. This can be
77 retrieved from inside of :c:func:`memcached_fetch_execute`. Cloning a
78 :c:type:`memcached_st` will copy the pointer to the clone.
79
80 .. c:type:: MEMCACHED_CALLBACK_MALLOC_FUNCTION
81 .. deprecated:: <0.32
82 Use :c:type:`memcached_set_memory_allocators` instead.
83
84 .. c:type:: MEMCACHED_CALLBACK_REALLOC_FUNCTION
85 .. deprecated:: <0.32
86 Use :c:type:`memcached_set_memory_allocators` instead.
87
88 .. c:type:: MEMCACHED_CALLBACK_FREE_FUNCTION
89 .. deprecated:: <0.32
90 Use :c:type:`memcached_set_memory_allocators` instead.
91
92 .. c:type:: MEMCACHED_CALLBACK_GET_FAILURE
93
94 This function implements the read through cache behavior. On failure of retrieval this callback will be called.
95
96 You are responsible for populating the result object provided. This result object will then be stored in the server and returned to the calling process.
97
98 You must clone the :c:type:`memcached_st` in order to
99 make use of it. The value will be stored only if you return
100 :c:type:`MEMCACHED_SUCCESS` or :c:type:`MEMCACHED_BUFFERED`. Returning
101 :c:type:`MEMCACHED_BUFFERED` will cause the object to be buffered and not sent
102 immediatly (if this is the default behavior based on your connection setup
103 this will happen automatically).
104
105 The prototype for this is:
106
107 .. c:function:: memcached_return_t (\*memcached_trigger_key)(memcached_st \*ptr, char \*key, size_t key_length, memcached_result_st \*result);
108
109
110
111 .. c:type:: MEMCACHED_CALLBACK_DELETE_TRIGGER
112
113 This function implements a trigger upon successful deletion of a key. The memcached_st structure will need to be cloned in order to make use of it.
114
115 The prototype for this is:
116
117 .. c:function:: typedef memcached_return_t (\*memcached_trigger_delete_key)(memcached_st \*ptr, char \*key, size_t key_length);
118
119
120
121
122 ------
123 RETURN
124 ------
125
126
127 :c:func:`memcached_callback_get` return the function or structure that was
128 provided. Upon error, nothing is set, null is returned, and the
129 :c:type:`memcached_return_t` argument is set to :c:type:`MEMCACHED_FAILURE`.
130
131 :c:func:`memcached_callback_set` returns :c:type:`MEMCACHED_SUCCESS` upon
132 successful setting, otherwise :c:type:`MEMCACHED_FAILURE` on error.
133
134
135 ----
136 HOME
137 ----
138
139
140 To find out more information please check:
141 `http://libmemcached.org/ <http://libmemcached.org/>`_
142
143
144 ------
145 AUTHOR
146 ------
147
148
149 Brian Aker, <brian@tangent.org>
150
151
152 --------
153 SEE ALSO
154 --------
155
156
157 :manpage:`memcached(1)` :manpage:`libmemcached(3)` :manpage:`memcached_strerror(3)`