cache.h revision 9b0e18da3d5c2290f90b285d122d368173f17c63
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * Copyright (C) 1999 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.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson ***** Module Info
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * 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,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson char *db_type, unsigned int db_argc, char **db_argv,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * 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
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * DNS_R_SUCCESS
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * DNS_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
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * separate dns_cache_add() interface instead would allow
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * more control over memory usage).
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * 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.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * DNS_R_SUCCESS
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * DNS_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.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * 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 loading
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * may or may not be preserved, and reads may return
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * either the old or the newly loaded data.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * DNS_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.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * 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.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * DNS_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.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson#endif /* DNS_CACHE_H */