Lines Matching refs:Cache
53 /* This code implements a small and *simple* DNS resolver cache.
55 * It is only used to cache DNS answers for a time defined by the smallest TTL
57 * to be a full DNS cache, since we plan to implement that in the future in a
69 * to keep an answer in the cache.
72 * (and should be solved by the later full DNS cache process).
78 * that a full DNS cache is expected to do.
82 * - the client calls _resolv_cache_get() to obtain a handle to the cache.
83 * this will initialize the cache on first usage. the result can be NULL
84 * if the cache is disabled.
93 * answer to the cache.
103 * this code is called if its value is "0", then the resolver cache is
108 /* default number of entries kept in the cache. This value has been
132 * * 2) we've made this a system-wide cache, so the cost is less (it's not
140 /* name of the system property that can be used to set the cache size */
150 /* set to 1 to debug cache operations */
406 * TTL : 32 : seconds to cache this RR (0=none)
587 * type of query we can cache, or 0 otherwise
988 /* cache entry. for simplicity, 'hash' and 'hlink' are inlined in this
1062 * keep the answer in the cache.
1081 // a response with no answers? Cache this negative result.
1161 /* allocate a new entry as a cache node */
1230 } Cache;
1234 Cache* cache;
1254 /* gets cache associated with a network, or NULL if none exists */
1258 _cache_flush_pending_requests_locked( struct resolv_cache* cache )
1261 if (cache) {
1262 ri = cache->pending_requests.next;
1273 cache->pending_requests.next = NULL;
1279 * the matching request completes, then update *cache and return 1. */
1281 _cache_check_pending_request_locked( struct resolv_cache** cache, Entry* key, unsigned netid )
1286 if (*cache && key) {
1287 ri = (*cache)->pending_requests.next;
1288 prev = &(*cache)->pending_requests;
1310 /* Must update *cache as it could have been deleted. */
1311 *cache = _find_named_cache_locked(netid);
1319 * matching the key has been added to the cache */
1321 _cache_notify_waiting_tid_locked( struct resolv_cache* cache, Entry* key )
1325 if (cache && key) {
1326 ri = cache->pending_requests.next;
1327 prev = &cache->pending_requests;
1346 /* notify the cache that the query failed */
1353 Cache* cache;
1360 cache = _find_named_cache_locked(netid);
1362 if (cache) {
1363 _cache_notify_waiting_tid_locked(cache, key);
1372 _cache_flush_locked( Cache* cache )
1376 for (nn = 0; nn < cache->max_entries; nn++)
1378 Entry** pnode = (Entry**) &cache->entries[nn];
1388 _cache_flush_pending_requests_locked(cache);
1390 cache->mru_list.mru_next = cache->mru_list.mru_prev = &cache->mru_list;
1391 cache->num_entries = 0;
1392 cache->last_id = 0;
1395 "*** DNS CACHE FLUSHED ***\n"
1406 // Don't use the cache in local mode. This is used by the proxy itself.
1410 XLOG("cache size: %d", cache_size);
1417 struct resolv_cache* cache;
1419 cache = calloc(sizeof(*cache), 1);
1420 if (cache) {
1421 cache->max_entries = _res_cache_get_max_entries();
1422 cache->entries = calloc(sizeof(*cache->entries), cache->max_entries);
1423 if (cache->entries) {
1424 cache->mru_list.mru_prev = cache->mru_list.mru_next = &cache->mru_list;
1425 XLOG("%s: cache created\n", __FUNCTION__);
1427 free(cache);
1428 cache = NULL;
1431 return cache;
1448 _cache_dump_mru( Cache* cache )
1453 p = _bprint(temp, end, "MRU LIST (%2d): ", cache->num_entries);
1454 for (e = cache->mru_list.mru_next; e != &cache->mru_list; e = e->mru_next)
1518 _cache_lookup_p( Cache* cache,
1521 int index = key->hash % cache->max_entries;
1522 Entry** pnode = (Entry**) &cache->entries[ index ];
1544 _cache_add_p( Cache* cache,
1549 e->id = ++cache->last_id;
1550 entry_mru_add(e, &cache->mru_list);
1551 cache->num_entries += 1;
1554 e->id, cache->num_entries);
1562 _cache_remove_p( Cache* cache,
1568 e->id, cache->num_entries-1);
1573 cache->num_entries -= 1;
1579 _cache_remove_oldest( Cache* cache )
1581 Entry* oldest = cache->mru_list.mru_prev;
1582 Entry** lookup = _cache_lookup_p(cache, oldest);
1589 XLOG("Cache full - removing oldest");
1592 _cache_remove_p(cache, lookup);
1597 static void _cache_remove_expired(Cache* cache) {
1601 for (e = cache->mru_list.mru_next; e != &cache->mru_list;) {
1604 Entry** lookup = _cache_lookup_p(cache, e);
1610 _cache_remove_p(cache, lookup);
1629 Cache* cache;
1636 /* we don't cache malformed queries */
1641 /* lookup cache */
1645 cache = _find_named_cache_locked(netid);
1646 if (cache == NULL) {
1654 lookup = _cache_lookup_p(cache, key);
1658 XLOG( "NOT IN CACHE");
1661 if (!_cache_check_pending_request_locked(&cache, key, netid) || cache == NULL) {
1664 lookup = _cache_lookup_p(cache, key);
1676 XLOG( " NOT IN CACHE (STALE ENTRY %p DISCARDED)", *lookup );
1678 _cache_remove_p(cache, lookup);
1693 if (e != cache->mru_list.mru_next) {
1695 entry_mru_add( e, &cache->mru_list );
1698 XLOG( "FOUND IN CACHE entry=%p", e );
1718 Cache* cache = NULL;
1729 cache = _find_named_cache_locked(netid);
1730 if (cache == NULL) {
1742 lookup = _cache_lookup_p(cache, key);
1746 XLOG("%s: ALREADY IN CACHE (%p) ? IGNORING ADD",
1751 if (cache->num_entries >= cache->max_entries) {
1752 _cache_remove_expired(cache);
1753 if (cache->num_entries >= cache->max_entries) {
1754 _cache_remove_oldest(cache);
1757 lookup = _cache_lookup_p(cache, key);
1760 XLOG("%s: ALREADY IN CACHE (%p) ? IGNORING ADD",
1771 _cache_add_p(cache, lookup, e);
1775 _cache_dump_mru(cache);
1778 if (cache != NULL) {
1779 _cache_notify_waiting_tid_locked(cache, key);
1801 /* look up the named cache, and creates one if needed */
1803 /* empty the named cache */
1805 /* empty the nameservers set for the named cache */
1820 /* the cache is disabled */
1831 struct resolv_cache* cache = _find_named_cache_locked(netid);
1832 if (!cache) {
1835 cache = _resolv_cache_create();
1836 if (cache) {
1837 cache_info->cache = cache;
1845 return cache;
1862 struct resolv_cache* cache = _find_named_cache_locked(netid);
1863 if (cache) {
1864 _cache_flush_locked(cache);
1884 _cache_flush_locked(cache_info->cache);
1885 free(cache_info->cache->entries);
1886 free(cache_info->cache);
1923 if (info != NULL) return info->cache;
1989 // creates the cache if not created
2013 // Flush the cache and reset the stats.
2032 // complex due to the zero-padding, and probably not worth the effort. Cache-flushing
2033 // however is not // necessary, since the stored cache entries do contain the domain, not
2149 // now do search domains. Note that we cache the offsets as this code runs alot