auth/gensec: make sure gensec_start_mech_by_authtype() resets SIGN/SEAL before starting
[Samba.git] / lib / util / memcache.h
blob11e59718c9f14d25ed9ddfbdd0af351c1da1a2e1
1 /*
2 Unix SMB/CIFS implementation.
3 In-memory cache
4 Copyright (C) Volker Lendecke 2007-2008
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.
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.
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/>.
20 #ifndef __MEMCACHE_H__
21 #define __MEMCACHE_H__
23 struct memcache;
26 * A memcache can store different subkeys with overlapping keys, the
27 * memcache_number becomes part of the key. Feel free to add caches of your
28 * own here.
30 * If you add talloc type caches, also note this in the switch statement in
31 * memcache_is_talloc().
34 enum memcache_number {
35 STAT_CACHE,
36 GETWD_CACHE,
37 GETPWNAM_CACHE, /* talloc */
38 MANGLE_HASH2_CACHE,
39 PDB_GETPWSID_CACHE, /* talloc */
40 SINGLETON_CACHE_TALLOC, /* talloc */
41 SINGLETON_CACHE,
42 SMB1_SEARCH_OFFSET_MAP
46 * Create a memcache structure. max_size is in bytes, if you set it 0 it will
47 * not forget anything.
50 struct memcache *memcache_init(TALLOC_CTX *mem_ctx, size_t max_size);
53 * If you set this global memcache, use it as the default cache when NULL is
54 * passed to the memcache functions below. This is a workaround for many
55 * situations where passing the cache everywhere would be a big hassle.
58 void memcache_set_global(struct memcache *cache);
61 * Add a data blob to the cache
64 void memcache_add(struct memcache *cache, enum memcache_number n,
65 DATA_BLOB key, DATA_BLOB value);
68 * Add a talloc object to the cache. The difference to memcache_add() is that
69 * when the objects is to be discared, talloc_free is called for it. Also
70 * talloc_move() ownership of the object to the cache.
72 * Please note that the current implementation has a fixed relationship
73 * between what cache subtypes store talloc objects and which ones store plain
74 * blobs. We can fix this, but for now we don't have a mixed use of blobs vs
75 * talloc objects in the cache types.
78 void memcache_add_talloc(struct memcache *cache, enum memcache_number n,
79 DATA_BLOB key, void *ptr);
82 * Delete an object from the cache
85 void memcache_delete(struct memcache *cache, enum memcache_number n,
86 DATA_BLOB key);
89 * Look up an object from the cache. Memory still belongs to the cache, so
90 * make a copy of it if needed.
93 bool memcache_lookup(struct memcache *cache, enum memcache_number n,
94 DATA_BLOB key, DATA_BLOB *value);
97 * Look up an object from the cache. Memory still belongs to the cache, so
98 * make a copy of it if needed.
101 void *memcache_lookup_talloc(struct memcache *cache, enum memcache_number n,
102 DATA_BLOB key);
105 * Flush a complete cache subset.
108 void memcache_flush(struct memcache *cache, enum memcache_number n);
110 #endif