cache.h revision 70c7f4fb4fc589b04a68d67479d34eecd99c1991
9e0d0a279b956cc2eae41c00a6846b0ca8c617c6Automatic Updater * Copyright (C) 2004-2007, 2009 Internet Systems Consortium, Inc. ("ISC")
499b34cea04a46823d003d4c0520c8b03e8513cbBrian Wellington * Copyright (C) 1999-2001 Internet Software Consortium.
ec5347e2c775f027573ce5648b910361aa926c01Automatic Updater * Permission to use, copy, modify, and/or distribute this software for any
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * purpose with or without fee is hereby granted, provided that the above
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * copyright notice and this permission notice appear in all copies.
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * PERFORMANCE OF THIS SOFTWARE.
70c7f4fb4fc589b04a68d67479d34eecd99c1991Evan Hunt/* $Id: cache.h,v 1.29 2011/03/03 04:42:25 each Exp $ */
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson ***** Module Info
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Defines dns_cache_t, the cache object.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li A cache object contains DNS data of a single class.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * Multiple classes will be handled by creating multiple
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * views, each with a different class and its own cache.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li See notes at the individual functions.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * Reliability:
70c7f4fb4fc589b04a68d67479d34eecd99c1991Evan Huntdns_cache_create(isc_mem_t *cmctx, isc_taskmgr_t *taskmgr,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson isc_timermgr_t *timermgr, dns_rdataclass_t rdclass,
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence const char *db_type, unsigned int db_argc, char **db_argv,
70c7f4fb4fc589b04a68d67479d34eecd99c1991Evan Huntdns_cache_create2(isc_mem_t *cmctx, isc_taskmgr_t *taskmgr,
70c7f4fb4fc589b04a68d67479d34eecd99c1991Evan Hunt isc_timermgr_t *timermgr, dns_rdataclass_t rdclass,
70c7f4fb4fc589b04a68d67479d34eecd99c1991Evan Hunt unsigned int db_argc, char **db_argv, dns_cache_t **cachep);
70c7f4fb4fc589b04a68d67479d34eecd99c1991Evan Huntdns_cache_create3(isc_mem_t *cmctx, isc_mem_t *hmctx, isc_taskmgr_t *taskmgr,
7781f25078c491a9650dec555bdc86cb0ed49861Tatuya JINMEI 神明達哉 isc_timermgr_t *timermgr, dns_rdataclass_t rdclass,
7781f25078c491a9650dec555bdc86cb0ed49861Tatuya JINMEI 神明達哉 const char *cachename, const char *db_type,
7781f25078c491a9650dec555bdc86cb0ed49861Tatuya JINMEI 神明達哉 unsigned int db_argc, char **db_argv, dns_cache_t **cachep);
70c7f4fb4fc589b04a68d67479d34eecd99c1991Evan Hunt * Create a new DNS cache.
70c7f4fb4fc589b04a68d67479d34eecd99c1991Evan Hunt * dns_cache_create2() will create a named cache.
70c7f4fb4fc589b04a68d67479d34eecd99c1991Evan Hunt * dns_cache_create3() will create a named cache using two separate memory
70c7f4fb4fc589b04a68d67479d34eecd99c1991Evan Hunt * contexts, one for cache data which can be cleaned and a separate one for
70c7f4fb4fc589b04a68d67479d34eecd99c1991Evan Hunt * memory allocated for the heap (which can grow without an upper limit and
70c7f4fb4fc589b04a68d67479d34eecd99c1991Evan Hunt * has no mechanism for shrinking).
70c7f4fb4fc589b04a68d67479d34eecd99c1991Evan Hunt * dns_cache_create() is a backward compatible version that internally
70c7f4fb4fc589b04a68d67479d34eecd99c1991Evan Hunt * specifies an empty cache name and a single memory context.
70c7f4fb4fc589b04a68d67479d34eecd99c1991Evan Hunt *\li 'cmctx' (and 'hmctx' if applicable) is a valid memory context.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li 'taskmgr' is a valid task manager and 'timermgr' is a valid timer
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * manager, or both are NULL. If NULL, no periodic cleaning of the
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * cache will take place.
7781f25078c491a9650dec555bdc86cb0ed49861Tatuya JINMEI 神明達哉 *\li 'cachename' is a valid string. This must not be NULL.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li 'cachep' is a valid pointer, and *cachep == NULL
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li '*cachep' is attached to the newly created cache
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li #ISC_R_SUCCESS
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li #ISC_R_NOMEMORY
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafssondns_cache_attach(dns_cache_t *cache, dns_cache_t **targetp);
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * Attach *targetp to cache.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li 'cache' is a valid cache.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li 'targetp' points to a NULL dns_cache_t *.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li *targetp is attached to cache.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * Detach *cachep from its cache.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li 'cachep' points to a valid cache.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li *cachep is NULL.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li If '*cachep' is the last reference to the cache,
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * all resources used by the cache will be freed
97404c1965ae83ecbfe9cf7b06f67dce5e28c588Andreas Gustafssondns_cache_attachdb(dns_cache_t *cache, dns_db_t **dbp);
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * Attach *dbp to the cache's database.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li This may be used to get a reference to the database for
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * the purpose of cache lookups (XXX currently it is also
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * the way to add data to the cache, but having a
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * separate dns_cache_add() interface instead would allow
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * more control over memory usage).
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * The caller should call dns_db_detach() on the reference
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * when it is no longer needed.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li 'cache' is a valid cache.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li 'dbp' points to a NULL dns_db *.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li *dbp is attached to the database.
4e1d3e67cdc76609bad5f0310ac48de10b442b9fMark Andrewsdns_cache_setfilename(dns_cache_t *cache, const char *filename);
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * If 'filename' is non-NULL, make the cache persistent.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * The cache's data will be stored in the given file.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * If 'filename' is NULL, make the cache non-persistent.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * Files that are no longer used are not unlinked automatically.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li #ISC_R_SUCCESS
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li #ISC_R_NOMEMORY
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li Various file-related failures
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * If the cache has a file name, load the cache contents from the file.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * Previous cache contents are not discarded.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * If no file name has been set, do nothing and return success.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li Multiple simultaneous attempts to load or dump the cache
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * will be serialized with respect to one another, but
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * the cache may be read and updated while the dump is
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * in progress. Updates performed during loading
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * may or may not be preserved, and reads may return
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * either the old or the newly loaded data.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li #ISC_R_SUCCESS
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \li Various failures depending on the database implementation type
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * If the cache has a file name, write the cache contents to disk,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * overwriting any preexisting file. If no file name has been set,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * do nothing and return success.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li Multiple simultaneous attempts to load or dump the cache
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * will be serialized with respect to one another, but
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * the cache may be read and updated while the dump is
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * in progress. Updates performed during the dump may
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * or may not be reflected in the dumped file.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li #ISC_R_SUCCESS
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \li Various failures depending on the database implementation type
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafssondns_cache_clean(dns_cache_t *cache, isc_stdtime_t now);
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * Force immediate cleaning of the cache, freeing all rdatasets
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * whose TTL has expired as of 'now' and that have no pending
8f79820c6930ee5ef6b4a54f36d2559400bdf47dAndreas Gustafssondns_cache_setcleaninginterval(dns_cache_t *cache, unsigned int interval);
8f79820c6930ee5ef6b4a54f36d2559400bdf47dAndreas Gustafsson * Set the periodic cache cleaning interval to 'interval' seconds.
7781f25078c491a9650dec555bdc86cb0ed49861Tatuya JINMEI 神明達哉dns_cache_getcleaninginterval(dns_cache_t *cache);
7781f25078c491a9650dec555bdc86cb0ed49861Tatuya JINMEI 神明達哉 * Get the periodic cache cleaning interval to 'interval' seconds.
7781f25078c491a9650dec555bdc86cb0ed49861Tatuya JINMEI 神明達哉dns_cache_getcachesize(dns_cache_t *cache);
7781f25078c491a9650dec555bdc86cb0ed49861Tatuya JINMEI 神明達哉 * Get the maximum cache size.
7781f25078c491a9650dec555bdc86cb0ed49861Tatuya JINMEI 神明達哉 * Get the cache name.
3a34b87c878990c6303358efd22265c2c5980c65Mark Andrewsdns_cache_setcachesize(dns_cache_t *cache, isc_uint32_t size);
50a3152b7088546418c8edc0c89eeaf48560b035Andreas Gustafsson * Set the maximum cache size. 0 means unlimited.
7781f25078c491a9650dec555bdc86cb0ed49861Tatuya JINMEI 神明達哉dns_cache_getcachesize(dns_cache_t *cache);
7781f25078c491a9650dec555bdc86cb0ed49861Tatuya JINMEI 神明達哉 * Get the maximum cache size.
c20ffa38dee7efa0dc01822d4bac5e41729b9b61Brian Wellington * Flushes all data from the cache.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li #ISC_R_SUCCESS
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li #ISC_R_NOMEMORY
6c8abf481df85a67c3f32f5f107b554d3ff5a3edMark Andrewsdns_cache_flushname(dns_cache_t *cache, dns_name_t *name);
6c8abf481df85a67c3f32f5f107b554d3ff5a3edMark Andrews * Flushes a given name from the cache.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li 'cache' to be valid.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li 'name' to be valid.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li #ISC_R_SUCCESS
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li #ISC_R_NOMEMORY
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li other error returns.
4be63b1fd8c18dbeca1648d6cf22fa14f057a469David Lawrence#endif /* DNS_CACHE_H */