Lines Matching refs:Cache
52 /* This code implements a small and *simple* DNS resolver cache.
54 * It is only used to cache DNS answers for a time defined by the smallest TTL
56 * to be a full DNS cache, since we plan to implement that in the future in a
68 * to keep an answer in the cache.
71 * (and should be solved by the later full DNS cache process).
77 * that a full DNS cache is expected to do.
81 * - the client calls _resolv_cache_get() to obtain a handle to the cache.
82 * this will initialize the cache on first usage. the result can be NULL
83 * if the cache is disabled.
92 * answer to the cache.
102 * this code is called if its value is "0", then the resolver cache is
107 /* default number of entries kept in the cache. This value has been
131 * * 2) we've made this a system-wide cache, so the cost is less (it's not
148 /* set to 1 to debug cache operations */
404 * TTL : 32 : seconds to cache this RR (0=none)
585 * type of query we can cache, or 0 otherwise
986 /* cache entry. for simplicity, 'hash' and 'hlink' are inlined in this
1060 * keep the answer in the cache.
1079 // a response with no answers? Cache this negative result.
1159 /* allocate a new entry as a cache node */
1228 } Cache;
1232 Cache* cache;
1252 /* gets cache associated with a network, or NULL if none exists */
1256 _cache_flush_pending_requests_locked( struct resolv_cache* cache )
1259 if (cache) {
1260 ri = cache->pending_requests.next;
1271 cache->pending_requests.next = NULL;
1277 * the matching request completes, then update *cache and return 1. */
1279 _cache_check_pending_request_locked( struct resolv_cache** cache, Entry* key, unsigned netid )
1284 if (*cache && key) {
1285 ri = (*cache)->pending_requests.next;
1286 prev = &(*cache)->pending_requests;
1308 /* Must update *cache as it could have been deleted. */
1309 *cache = _find_named_cache_locked(netid);
1317 * matching the key has been added to the cache */
1319 _cache_notify_waiting_tid_locked( struct resolv_cache* cache, Entry* key )
1323 if (cache && key) {
1324 ri = cache->pending_requests.next;
1325 prev = &cache->pending_requests;
1344 /* notify the cache that the query failed */
1351 Cache* cache;
1358 cache = _find_named_cache_locked(netid);
1360 if (cache) {
1361 _cache_notify_waiting_tid_locked(cache, key);
1370 _cache_flush_locked( Cache* cache )
1374 for (nn = 0; nn < cache->max_entries; nn++)
1376 Entry** pnode = (Entry**) &cache->entries[nn];
1386 _cache_flush_pending_requests_locked(cache);
1388 cache->mru_list.mru_next = cache->mru_list.mru_prev = &cache->mru_list;
1389 cache->num_entries = 0;
1390 cache->last_id = 0;
1393 "*** DNS CACHE FLUSHED ***\n"
1404 // Don't use the cache in local mode. This is used by the proxy itself.
1408 XLOG("cache size: %d", cache_size);
1415 struct resolv_cache* cache;
1417 cache = calloc(sizeof(*cache), 1);
1418 if (cache) {
1419 cache->max_entries = _res_cache_get_max_entries();
1420 cache->entries = calloc(sizeof(*cache->entries), cache->max_entries);
1421 if (cache->entries) {
1422 cache->mru_list.mru_prev = cache->mru_list.mru_next = &cache->mru_list;
1423 XLOG("%s: cache created\n", __FUNCTION__);
1425 free(cache);
1426 cache = NULL;
1429 return cache;
1446 _cache_dump_mru( Cache* cache )
1451 p = _bprint(temp, end, "MRU LIST (%2d): ", cache->num_entries);
1452 for (e = cache->mru_list.mru_next; e != &cache->mru_list; e = e->mru_next)
1516 _cache_lookup_p( Cache* cache,
1519 int index = key->hash % cache->max_entries;
1520 Entry** pnode = (Entry**) &cache->entries[ index ];
1542 _cache_add_p( Cache* cache,
1547 e->id = ++cache->last_id;
1548 entry_mru_add(e, &cache->mru_list);
1549 cache->num_entries += 1;
1552 e->id, cache->num_entries);
1560 _cache_remove_p( Cache* cache,
1566 e->id, cache->num_entries-1);
1571 cache->num_entries -= 1;
1577 _cache_remove_oldest( Cache* cache )
1579 Entry* oldest = cache->mru_list.mru_prev;
1580 Entry** lookup = _cache_lookup_p(cache, oldest);
1587 XLOG("Cache full - removing oldest");
1590 _cache_remove_p(cache, lookup);
1595 static void _cache_remove_expired(Cache* cache) {
1599 for (e = cache->mru_list.mru_next; e != &cache->mru_list;) {
1602 Entry** lookup = _cache_lookup_p(cache, e);
1608 _cache_remove_p(cache, lookup);
1627 Cache* cache;
1634 /* we don't cache malformed queries */
1639 /* lookup cache */
1643 cache = _find_named_cache_locked(netid);
1644 if (cache == NULL) {
1652 lookup = _cache_lookup_p(cache, key);
1656 XLOG( "NOT IN CACHE");
1659 if (!_cache_check_pending_request_locked(&cache, key, netid) || cache == NULL) {
1662 lookup = _cache_lookup_p(cache, key);
1674 XLOG( " NOT IN CACHE (STALE ENTRY %p DISCARDED)", *lookup );
1676 _cache_remove_p(cache, lookup);
1691 if (e != cache->mru_list.mru_next) {
1693 entry_mru_add( e, &cache->mru_list );
1696 XLOG( "FOUND IN CACHE entry=%p", e );
1716 Cache* cache = NULL;
1727 cache = _find_named_cache_locked(netid);
1728 if (cache == NULL) {
1740 lookup = _cache_lookup_p(cache, key);
1744 XLOG("%s: ALREADY IN CACHE (%p) ? IGNORING ADD",
1749 if (cache->num_entries >= cache->max_entries) {
1750 _cache_remove_expired(cache);
1751 if (cache->num_entries >= cache->max_entries) {
1752 _cache_remove_oldest(cache);
1755 lookup = _cache_lookup_p(cache, key);
1758 XLOG("%s: ALREADY IN CACHE (%p) ? IGNORING ADD",
1769 _cache_add_p(cache, lookup, e);
1773 _cache_dump_mru(cache);
1776 if (cache != NULL) {
1777 _cache_notify_waiting_tid_locked(cache, key);
1799 /* look up the named cache, and creates one if needed */
1801 /* empty the named cache */
1803 /* empty the nameservers set for the named cache */
1818 /* the cache is disabled */
1829 struct resolv_cache* cache = _find_named_cache_locked(netid);
1830 if (!cache) {
1833 cache = _resolv_cache_create();
1834 if (cache) {
1835 cache_info->cache = cache;
1843 return cache;
1860 struct resolv_cache* cache = _find_named_cache_locked(netid);
1861 if (cache) {
1862 _cache_flush_locked(cache);
1882 _cache_flush_locked(cache_info->cache);
1883 free(cache_info->cache->entries);
1884 free(cache_info->cache);
1921 if (info != NULL) return info->cache;
1987 // creates the cache if not created
2030 // complex due to the zero-padding, and probably not worth the effort. Cache-flushing
2031 // however is not // necessary, since the stored cache entries do contain the domain, not
2147 // now do search domains. Note that we cache the offsets as this code runs alot