| 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 "includes.h"
 | 
|---|
| 24 | 
 | 
|---|
| 25 | struct memcache;
 | 
|---|
| 26 | 
 | 
|---|
| 27 | /*
 | 
|---|
| 28 |  * A memcache can store different subkeys with overlapping keys, the
 | 
|---|
| 29 |  * memcache_number becomes part of the key. Feel free to add caches of your
 | 
|---|
| 30 |  * own here.
 | 
|---|
| 31 |  *
 | 
|---|
| 32 |  * If you add talloc type caches, also note this in the switch statement in
 | 
|---|
| 33 |  * memcache_is_talloc().
 | 
|---|
| 34 |  */
 | 
|---|
| 35 | 
 | 
|---|
| 36 | enum memcache_number {
 | 
|---|
| 37 |         STAT_CACHE,
 | 
|---|
| 38 |         UID_SID_CACHE,
 | 
|---|
| 39 |         SID_UID_CACHE,
 | 
|---|
| 40 |         GID_SID_CACHE,
 | 
|---|
| 41 |         SID_GID_CACHE,
 | 
|---|
| 42 |         GETWD_CACHE,
 | 
|---|
| 43 |         GETPWNAM_CACHE,         /* talloc */
 | 
|---|
| 44 |         MANGLE_HASH2_CACHE,
 | 
|---|
| 45 |         PDB_GETPWSID_CACHE,     /* talloc */
 | 
|---|
| 46 |         SINGLETON_CACHE_TALLOC, /* talloc */
 | 
|---|
| 47 |         SINGLETON_CACHE
 | 
|---|
| 48 | };
 | 
|---|
| 49 | 
 | 
|---|
| 50 | /*
 | 
|---|
| 51 |  * Create a memcache structure. max_size is in bytes, if you set it 0 it will
 | 
|---|
| 52 |  * not forget anything.
 | 
|---|
| 53 |  */
 | 
|---|
| 54 | 
 | 
|---|
| 55 | struct memcache *memcache_init(TALLOC_CTX *mem_ctx, size_t max_size);
 | 
|---|
| 56 | 
 | 
|---|
| 57 | /*
 | 
|---|
| 58 |  * If you set this global memcache, use it as the default cache when NULL is
 | 
|---|
| 59 |  * passed to the memcache functions below. This is a workaround for many
 | 
|---|
| 60 |  * situations where passing the cache everywhere would be a big hassle.
 | 
|---|
| 61 |  */
 | 
|---|
| 62 | 
 | 
|---|
| 63 | void memcache_set_global(struct memcache *cache);
 | 
|---|
| 64 | 
 | 
|---|
| 65 | /*
 | 
|---|
| 66 |  * Add a data blob to the cache
 | 
|---|
| 67 |  */
 | 
|---|
| 68 | 
 | 
|---|
| 69 | void memcache_add(struct memcache *cache, enum memcache_number n,
 | 
|---|
| 70 |                   DATA_BLOB key, DATA_BLOB value);
 | 
|---|
| 71 | 
 | 
|---|
| 72 | /*
 | 
|---|
| 73 |  * Add a talloc object to the cache. The difference to memcache_add() is that
 | 
|---|
| 74 |  * when the objects is to be discared, talloc_free is called for it. Also
 | 
|---|
| 75 |  * talloc_move() ownership of the object to the cache.
 | 
|---|
| 76 |  *
 | 
|---|
| 77 |  * Please note that the current implementation has a fixed relationship
 | 
|---|
| 78 |  * between what cache subtypes store talloc objects and which ones store plain
 | 
|---|
| 79 |  * blobs. We can fix this, but for now we don't have a mixed use of blobs vs
 | 
|---|
| 80 |  * talloc objects in the cache types.
 | 
|---|
| 81 |  */
 | 
|---|
| 82 | 
 | 
|---|
| 83 | void memcache_add_talloc(struct memcache *cache, enum memcache_number n,
 | 
|---|
| 84 |                          DATA_BLOB key, void *ptr);
 | 
|---|
| 85 | 
 | 
|---|
| 86 | /*
 | 
|---|
| 87 |  * Delete an object from the cache
 | 
|---|
| 88 |  */
 | 
|---|
| 89 | 
 | 
|---|
| 90 | void memcache_delete(struct memcache *cache, enum memcache_number n,
 | 
|---|
| 91 |                      DATA_BLOB key);
 | 
|---|
| 92 | 
 | 
|---|
| 93 | /*
 | 
|---|
| 94 |  * Look up an object from the cache. Memory still belongs to the cache, so
 | 
|---|
| 95 |  * make a copy of it if needed.
 | 
|---|
| 96 |  */
 | 
|---|
| 97 | 
 | 
|---|
| 98 | bool memcache_lookup(struct memcache *cache, enum memcache_number n,
 | 
|---|
| 99 |                      DATA_BLOB key, DATA_BLOB *value);
 | 
|---|
| 100 | 
 | 
|---|
| 101 | /*
 | 
|---|
| 102 |  * Look up an object from the cache. Memory still belongs to the cache, so
 | 
|---|
| 103 |  * make a copy of it if needed.
 | 
|---|
| 104 |  */
 | 
|---|
| 105 | 
 | 
|---|
| 106 | void *memcache_lookup_talloc(struct memcache *cache, enum memcache_number n,
 | 
|---|
| 107 |                              DATA_BLOB key);
 | 
|---|
| 108 | 
 | 
|---|
| 109 | /*
 | 
|---|
| 110 |  * Flush a complete cache subset.
 | 
|---|
| 111 |  */
 | 
|---|
| 112 | 
 | 
|---|
| 113 | void memcache_flush(struct memcache *cache, enum memcache_number n);
 | 
|---|
| 114 | 
 | 
|---|
| 115 | #endif
 | 
|---|