2007-12-18 12:07:08 +03:00
/*
Unix SMB / CIFS implementation .
In - memory cache
2008-01-03 12:24:11 +03:00
Copyright ( C ) Volker Lendecke 2007 - 2008
2007-12-18 12:07:08 +03:00
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation ; either version 3 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
2007-12-19 17:45:22 +03:00
# ifndef __MEMCACHE_H__
# define __MEMCACHE_H__
2007-12-18 12:07:08 +03:00
2016-11-16 19:13:12 +03:00
# include <talloc.h>
# include "lib/util/data_blob.h"
2007-12-18 12:07:08 +03:00
struct memcache ;
2008-01-03 12:24:11 +03:00
/*
* A memcache can store different subkeys with overlapping keys , the
* memcache_number becomes part of the key . Feel free to add caches of your
* own here .
*
* If you add talloc type caches , also note this in the switch statement in
* memcache_is_talloc ( ) .
*/
2007-12-18 12:07:08 +03:00
enum memcache_number {
STAT_CACHE ,
2014-03-10 18:41:32 +04:00
GENCACHE_RAM ,
2007-12-18 12:07:08 +03:00
GETWD_CACHE ,
2007-12-20 16:41:58 +03:00
GETPWNAM_CACHE , /* talloc */
2007-12-20 18:05:57 +03:00
MANGLE_HASH2_CACHE ,
2007-12-28 15:13:29 +03:00
PDB_GETPWSID_CACHE , /* talloc */
2007-12-28 19:24:39 +03:00
SINGLETON_CACHE_TALLOC , /* talloc */
2014-01-12 01:58:46 +04:00
SINGLETON_CACHE ,
2015-04-02 21:19:22 +03:00
SMB1_SEARCH_OFFSET_MAP ,
2016-10-18 22:37:19 +03:00
SHARE_MODE_LOCK_CACHE , /* talloc */
2018-05-16 23:05:36 +03:00
VIRUSFILTER_SCAN_RESULTS_CACHE_TALLOC , /* talloc */
DFREE_CACHE ,
2007-12-18 12:07:08 +03:00
} ;
2008-01-03 12:24:11 +03:00
/*
* Create a memcache structure . max_size is in bytes , if you set it 0 it will
* not forget anything .
*/
2007-12-18 12:07:08 +03:00
struct memcache * memcache_init ( TALLOC_CTX * mem_ctx , size_t max_size ) ;
2008-01-03 12:24:11 +03:00
/*
* If you set this global memcache , use it as the default cache when NULL is
* passed to the memcache functions below . This is a workaround for many
* situations where passing the cache everywhere would be a big hassle .
*/
2007-12-20 12:55:45 +03:00
void memcache_set_global ( struct memcache * cache ) ;
2008-01-03 12:24:11 +03:00
/*
* Add a data blob to the cache
*/
2007-12-18 12:07:08 +03:00
void memcache_add ( struct memcache * cache , enum memcache_number n ,
DATA_BLOB key , DATA_BLOB value ) ;
2008-01-03 12:24:11 +03:00
/*
* Add a talloc object to the cache . The difference to memcache_add ( ) is that
* when the objects is to be discared , talloc_free is called for it . Also
* talloc_move ( ) ownership of the object to the cache .
*
* Please note that the current implementation has a fixed relationship
* between what cache subtypes store talloc objects and which ones store plain
* blobs . We can fix this , but for now we don ' t have a mixed use of blobs vs
* talloc objects in the cache types .
*/
2007-12-20 16:41:58 +03:00
void memcache_add_talloc ( struct memcache * cache , enum memcache_number n ,
DATA_BLOB key , void * ptr ) ;
2008-01-03 12:24:11 +03:00
/*
* Delete an object from the cache
*/
2007-12-18 12:07:08 +03:00
void memcache_delete ( struct memcache * cache , enum memcache_number n ,
DATA_BLOB key ) ;
2008-01-03 12:24:11 +03:00
/*
* Look up an object from the cache . Memory still belongs to the cache , so
* make a copy of it if needed .
*/
2007-12-18 12:07:08 +03:00
bool memcache_lookup ( struct memcache * cache , enum memcache_number n ,
DATA_BLOB key , DATA_BLOB * value ) ;
2008-01-03 12:24:11 +03:00
/*
* Look up an object from the cache . Memory still belongs to the cache , so
* make a copy of it if needed .
*/
2007-12-20 16:41:58 +03:00
void * memcache_lookup_talloc ( struct memcache * cache , enum memcache_number n ,
DATA_BLOB key ) ;
2008-01-03 12:24:11 +03:00
/*
* Flush a complete cache subset .
*/
2007-12-18 12:07:08 +03:00
void memcache_flush ( struct memcache * cache , enum memcache_number n ) ;
# endif