debug: add an empty line
[samba.git] / lib / util / memcache.h
1 /*
2    Unix SMB/CIFS implementation.
3    In-memory cache
4    Copyright (C) Volker Lendecke 2007-2008
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef __MEMCACHE_H__
21 #define __MEMCACHE_H__
22
23 #include <talloc.h>
24 #include "lib/util/data_blob.h"
25
26 struct memcache;
27
28 /*
29  * A memcache can store different subkeys with overlapping keys, the
30  * memcache_number becomes part of the key. Feel free to add caches of your
31  * own here.
32  *
33  * If you add talloc type caches, also note this in the switch statement in
34  * memcache_is_talloc().
35  */
36
37 enum memcache_number {
38         STAT_CACHE,
39         GENCACHE_RAM,
40         GETWD_CACHE,
41         GETPWNAM_CACHE,         /* talloc */
42         MANGLE_HASH2_CACHE,
43         PDB_GETPWSID_CACHE,     /* talloc */
44         SINGLETON_CACHE_TALLOC, /* talloc */
45         SINGLETON_CACHE,
46         SMB1_SEARCH_OFFSET_MAP,
47         SHARE_MODE_LOCK_CACHE,  /* talloc */
48         VIRUSFILTER_SCAN_RESULTS_CACHE_TALLOC, /* talloc */
49         DFREE_CACHE,
50 };
51
52 /*
53  * Create a memcache structure. max_size is in bytes, if you set it 0 it will
54  * not forget anything.
55  */
56
57 struct memcache *memcache_init(TALLOC_CTX *mem_ctx, size_t max_size);
58
59 /*
60  * If you set this global memcache, use it as the default cache when NULL is
61  * passed to the memcache functions below. This is a workaround for many
62  * situations where passing the cache everywhere would be a big hassle.
63  */
64
65 void memcache_set_global(struct memcache *cache);
66
67 /*
68  * Add a data blob to the cache
69  */
70
71 void memcache_add(struct memcache *cache, enum memcache_number n,
72                   DATA_BLOB key, DATA_BLOB value);
73
74 /*
75  * Add a talloc object to the cache. The difference to memcache_add() is that
76  * when the objects is to be discared, talloc_free is called for it. Also
77  * talloc_move() ownership of the object to the cache.
78  *
79  * Please note that the current implementation has a fixed relationship
80  * between what cache subtypes store talloc objects and which ones store plain
81  * blobs. We can fix this, but for now we don't have a mixed use of blobs vs
82  * talloc objects in the cache types.
83  */
84
85 void memcache_add_talloc(struct memcache *cache, enum memcache_number n,
86                          DATA_BLOB key, void *ptr);
87
88 /*
89  * Delete an object from the cache
90  */
91
92 void memcache_delete(struct memcache *cache, enum memcache_number n,
93                      DATA_BLOB key);
94
95 /*
96  * Look up an object from the cache. Memory still belongs to the cache, so
97  * make a copy of it if needed.
98  */
99
100 bool memcache_lookup(struct memcache *cache, enum memcache_number n,
101                      DATA_BLOB key, DATA_BLOB *value);
102
103 /*
104  * Look up an object from the cache. Memory still belongs to the cache, so
105  * make a copy of it if needed.
106  */
107
108 void *memcache_lookup_talloc(struct memcache *cache, enum memcache_number n,
109                              DATA_BLOB key);
110
111 /*
112  * Flush a complete cache subset.
113  */
114
115 void memcache_flush(struct memcache *cache, enum memcache_number n);
116
117 #endif