2 * Copyright (C) 2004-2007, 2009, 2011, 2012 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2001 Internet Software Consortium.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
29 * Defines dns_cache_t, the cache object.
32 *\li A cache object contains DNS data of a single class.
33 * Multiple classes will be handled by creating multiple
34 * views, each with a different class and its own cache.
37 *\li See notes at the individual functions.
53 #include <isc/stdtime.h>
55 #include <dns/types.h>
64 dns_cache_create(isc_mem_t *cmctx, isc_taskmgr_t *taskmgr,
65 isc_timermgr_t *timermgr, dns_rdataclass_t rdclass,
66 const char *db_type, unsigned int db_argc, char **db_argv,
67 dns_cache_t **cachep);
69 dns_cache_create2(isc_mem_t *cmctx, isc_taskmgr_t *taskmgr,
70 isc_timermgr_t *timermgr, dns_rdataclass_t rdclass,
71 const char *cachename, const char *db_type,
72 unsigned int db_argc, char **db_argv, dns_cache_t **cachep);
74 dns_cache_create3(isc_mem_t *cmctx, isc_mem_t *hmctx, isc_taskmgr_t *taskmgr,
75 isc_timermgr_t *timermgr, dns_rdataclass_t rdclass,
76 const char *cachename, const char *db_type,
77 unsigned int db_argc, char **db_argv, dns_cache_t **cachep);
79 * Create a new DNS cache.
81 * dns_cache_create2() will create a named cache.
83 * dns_cache_create3() will create a named cache using two separate memory
84 * contexts, one for cache data which can be cleaned and a separate one for
85 * memory allocated for the heap (which can grow without an upper limit and
86 * has no mechanism for shrinking).
88 * dns_cache_create() is a backward compatible version that internally
89 * specifies an empty cache name and a single memory context.
93 *\li 'cmctx' (and 'hmctx' if applicable) is a valid memory context.
95 *\li 'taskmgr' is a valid task manager and 'timermgr' is a valid timer
96 * manager, or both are NULL. If NULL, no periodic cleaning of the
97 * cache will take place.
99 *\li 'cachename' is a valid string. This must not be NULL.
101 *\li 'cachep' is a valid pointer, and *cachep == NULL
105 *\li '*cachep' is attached to the newly created cache
114 dns_cache_attach(dns_cache_t *cache, dns_cache_t **targetp);
116 * Attach *targetp to cache.
120 *\li 'cache' is a valid cache.
122 *\li 'targetp' points to a NULL dns_cache_t *.
126 *\li *targetp is attached to cache.
130 dns_cache_detach(dns_cache_t **cachep);
132 * Detach *cachep from its cache.
136 *\li 'cachep' points to a valid cache.
140 *\li *cachep is NULL.
142 *\li If '*cachep' is the last reference to the cache,
143 * all resources used by the cache will be freed
147 dns_cache_attachdb(dns_cache_t *cache, dns_db_t **dbp);
149 * Attach *dbp to the cache's database.
153 *\li This may be used to get a reference to the database for
154 * the purpose of cache lookups (XXX currently it is also
155 * the way to add data to the cache, but having a
156 * separate dns_cache_add() interface instead would allow
157 * more control over memory usage).
158 * The caller should call dns_db_detach() on the reference
159 * when it is no longer needed.
163 *\li 'cache' is a valid cache.
165 *\li 'dbp' points to a NULL dns_db *.
169 *\li *dbp is attached to the database.
174 dns_cache_setfilename(dns_cache_t *cache, const char *filename);
176 * If 'filename' is non-NULL, make the cache persistent.
177 * The cache's data will be stored in the given file.
178 * If 'filename' is NULL, make the cache non-persistent.
179 * Files that are no longer used are not unlinked automatically.
184 *\li Various file-related failures
188 dns_cache_load(dns_cache_t *cache);
190 * If the cache has a file name, load the cache contents from the file.
191 * Previous cache contents are not discarded.
192 * If no file name has been set, do nothing and return success.
195 *\li Multiple simultaneous attempts to load or dump the cache
196 * will be serialized with respect to one another, but
197 * the cache may be read and updated while the dump is
198 * in progress. Updates performed during loading
199 * may or may not be preserved, and reads may return
200 * either the old or the newly loaded data.
205 * \li Various failures depending on the database implementation type
209 dns_cache_dump(dns_cache_t *cache);
211 * If the cache has a file name, write the cache contents to disk,
212 * overwriting any preexisting file. If no file name has been set,
213 * do nothing and return success.
216 *\li Multiple simultaneous attempts to load or dump the cache
217 * will be serialized with respect to one another, but
218 * the cache may be read and updated while the dump is
219 * in progress. Updates performed during the dump may
220 * or may not be reflected in the dumped file.
225 * \li Various failures depending on the database implementation type
229 dns_cache_clean(dns_cache_t *cache, isc_stdtime_t now);
231 * Force immediate cleaning of the cache, freeing all rdatasets
232 * whose TTL has expired as of 'now' and that have no pending
237 dns_cache_setcleaninginterval(dns_cache_t *cache, unsigned int interval);
239 * Set the periodic cache cleaning interval to 'interval' seconds.
243 dns_cache_getcleaninginterval(dns_cache_t *cache);
245 * Get the periodic cache cleaning interval to 'interval' seconds.
249 dns_cache_getcachesize(dns_cache_t *cache);
251 * Get the maximum cache size.
255 dns_cache_getname(dns_cache_t *cache);
257 * Get the cache name.
261 dns_cache_setcachesize(dns_cache_t *cache, isc_uint32_t size);
263 * Set the maximum cache size. 0 means unlimited.
267 dns_cache_getcachesize(dns_cache_t *cache);
269 * Get the maximum cache size.
273 dns_cache_flush(dns_cache_t *cache);
275 * Flushes all data from the cache.
283 dns_cache_flushname(dns_cache_t *cache, dns_name_t *name);
285 * Flushes a given name from the cache.
288 *\li 'cache' to be valid.
289 *\li 'name' to be valid.
294 *\li other error returns.
299 #endif /* DNS_CACHE_H */