cache.h revision 6c8abf481df85a67c3f32f5f107b554d3ff5a3ed
499b34cea04a46823d003d4c0520c8b03e8513cbBrian Wellington * Copyright (C) 1999-2001 Internet Software Consortium.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * Permission to use, copy, modify, and 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.
15a44745412679c30a6d022733925af70a38b715David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
15a44745412679c30a6d022733925af70a38b715David Lawrence * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
15a44745412679c30a6d022733925af70a38b715David Lawrence * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
15a44745412679c30a6d022733925af70a38b715David Lawrence * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
15a44745412679c30a6d022733925af70a38b715David Lawrence * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
15a44745412679c30a6d022733925af70a38b715David Lawrence * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
15a44745412679c30a6d022733925af70a38b715David Lawrence * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
15a44745412679c30a6d022733925af70a38b715David Lawrence * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
6c8abf481df85a67c3f32f5f107b554d3ff5a3edMark Andrews/* $Id: cache.h,v 1.18 2001/11/27 03:10:31 marka Exp $ */
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson ***** Module Info
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Defines dns_cache_t, the cache object.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * 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.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * See notes at the individual functions.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * Reliability:
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafssondns_cache_create(isc_mem_t *mctx, 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,
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Create a new DNS cache.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * 'mctx' is a valid memory context
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * '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.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * 'cachep' is a valid pointer, and *cachep == NULL
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * '*cachep' is attached to the newly created cache
c1a2cfef7f9156ffd15ded6cca6429a174319cc1Michael Graff * ISC_R_SUCCESS
c1a2cfef7f9156ffd15ded6cca6429a174319cc1Michael Graff * ISC_R_NOMEMORY
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafssondns_cache_attach(dns_cache_t *cache, dns_cache_t **targetp);
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * Attach *targetp to cache.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * 'cache' is a valid cache.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * 'targetp' points to a NULL dns_cache_t *.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * *targetp is attached to cache.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * Detach *cachep from its cache.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * 'cachep' points to a valid cache.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * *cachep is NULL.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * If '*cachep' is the last reference to the cache,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * 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.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * 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.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * 'cache' is a valid cache.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * 'dbp' points to a NULL dns_db *.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * *dbp is attached to the database.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafssondns_cache_setfilename(dns_cache_t *cahce, 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.
c1a2cfef7f9156ffd15ded6cca6429a174319cc1Michael Graff * ISC_R_SUCCESS
c1a2cfef7f9156ffd15ded6cca6429a174319cc1Michael Graff * ISC_R_NOMEMORY
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * 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.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * 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.
c1a2cfef7f9156ffd15ded6cca6429a174319cc1Michael Graff * ISC_R_SUCCESS
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * 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.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * 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.
c1a2cfef7f9156ffd15ded6cca6429a174319cc1Michael Graff * ISC_R_SUCCESS
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * 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.
3a34b87c878990c6303358efd22265c2c5980c65Mark Andrewsdns_cache_setcachesize(dns_cache_t *cache, isc_uint32_t size);
50a3152b7088546418c8edc0c89eeaf48560b035Andreas Gustafsson * Set the maximum cache size. 0 means unlimited.
c20ffa38dee7efa0dc01822d4bac5e41729b9b61Brian Wellington * Flushes all data from the cache.
c20ffa38dee7efa0dc01822d4bac5e41729b9b61Brian Wellington * ISC_R_SUCCESS
c20ffa38dee7efa0dc01822d4bac5e41729b9b61Brian Wellington * ISC_R_NOMEMORY
6c8abf481df85a67c3f32f5f107b554d3ff5a3edMark Andrewsdns_cache_flushname(dns_cache_t *cache, dns_name_t *name);
6c8abf481df85a67c3f32f5f107b554d3ff5a3edMark Andrews * Flushes a given name from the cache.
6c8abf481df85a67c3f32f5f107b554d3ff5a3edMark Andrews * 'cache' to be valid.
6c8abf481df85a67c3f32f5f107b554d3ff5a3edMark Andrews * 'name' to be valid.
6c8abf481df85a67c3f32f5f107b554d3ff5a3edMark Andrews * ISC_R_SUCCESS
6c8abf481df85a67c3f32f5f107b554d3ff5a3edMark Andrews * ISC_R_NOMEMORY
6c8abf481df85a67c3f32f5f107b554d3ff5a3edMark Andrews * other error returns.
4be63b1fd8c18dbeca1648d6cf22fa14f057a469David Lawrence#endif /* DNS_CACHE_H */