Home | History | Annotate | Download | only in resolv

Lines Matching full:cache

35 /* This code implements a small and *simple* DNS resolver cache.
37 * It is only used to cache DNS answers for a maximum of CONFIG_SECONDS seconds
38 * in order to reduce DNS traffic. It is not supposed to be a full DNS cache,
52 * CONFIG_SECONDS will be kept in the cache anyway.
55 * (and should be solved by the later full DNS cache process).
61 * that a full DNS cache is expected to do.
65 * - the client calls _resolv_cache_get() to obtain a handle to the cache.
66 * this will initialize the cache on first usage. the result can be NULL
67 * if the cache is disabled.
76 * answer to the cache.
84 * - when network settings change, the cache must be flushed since the list
94 * that the cache is only flushed once per network change.
98 * this code is called if its value is "0", then the resolver cache is
107 /* maximum number of entries kept in the cache. This value has been
138 /* set to 1 to debug cache operations */
389 * TTL : 32 : seconds to cache this RR (0=none)
572 * type of query we can cache, or 0 otherwise
975 /* cache entry. for simplicity, 'hash' and 'hlink' are inlined in this
1052 /* allocate a new entry as a cache node */
1115 } Cache;
1121 _cache_flush_locked( Cache* cache )
1128 Entry** pnode = &cache->entries[nn];
1137 cache->mru_list.mru_next = cache->mru_list.mru_prev = &cache->mru_list;
1138 cache->num_entries = 0;
1139 cache->last_id = 0;
1142 "*** DNS CACHE FLUSHED ***\n"
1149 struct resolv_cache* cache;
1151 cache = calloc(sizeof(*cache), 1);
1152 if (cache) {
1153 cache->generation = ~0U;
1154 pthread_mutex_init( &cache->lock, NULL );
1155 cache->mru_list.mru_prev = cache->mru_list.mru_next = &cache->mru_list;
1156 XLOG("%s: cache created\n", __FUNCTION__);
1158 return cache;
1175 _cache_dump_mru( Cache* cache )
1180 p = _bprint(temp, end, "MRU LIST (%2d): ", cache->num_entries);
1181 for (e = cachecache->mru_list; e = e->mru_next)
1209 _cache_lookup_p( Cache* cache,
1213 Entry** pnode = &cache->entries[ key->hash % MAX_HASH_ENTRIES ];
1235 _cache_add_p( Cache* cache,
1240 e->id = ++cache->last_id;
1241 entry_mru_add(e, &cache->mru_list);
1242 cache->num_entries += 1;
1245 e->id, cache->num_entries);
1253 _cache_remove_p( Cache* cache,
1259 e->id, cache->num_entries-1);
1264 cache->num_entries -= 1;
1270 _cache_remove_oldest( Cache* cache )
1272 Entry* oldest = cache->mru_list.mru_prev;
1273 Entry** lookup = _cache_lookup_p(cache, oldest);
1279 _cache_remove_p(cache, lookup);
1284 _resolv_cache_lookup( struct resolv_cache* cache,
1303 /* we don't cache malformed queries */
1308 /* lookup cache */
1309 pthread_mutex_lock( &cache->lock );
1314 lookup = _cache_lookup_p(cache, key);
1318 XLOG( "NOT IN CACHE");
1326 XLOG( " NOT IN CACHE (STALE ENTRY %p DISCARDED)", *lookup );
1327 _cache_remove_p(cache, lookup);
1342 if (e != cache->mru_list.mru_next) {
1344 entry_mru_add( e, &cache->mru_list );
1347 XLOG( "FOUND IN CACHE entry=%p", e );
1351 pthread_mutex_unlock( &cache->lock );
1357 _resolv_cache_add( struct resolv_cache* cache,
1374 pthread_mutex_lock( &cache->lock );
1383 lookup = _cache_lookup_p(cache, key);
1387 XLOG("%s: ALREADY IN CACHE (%p) ? IGNORING ADD",
1392 if (cache->num_entries >= CONFIG_MAX_ENTRIES) {
1393 _cache_remove_oldest(cache);
1395 lookup = _cache_lookup_p(cache, key);
1398 XLOG("%s: ALREADY IN CACHE (%p) ? IGNORING ADD",
1406 _cache_add_p(cache, lookup, e);
1409 _cache_dump_mru(cache);
1412 pthread_mutex_unlock( &cache->lock );
1432 /* the cache is disabled */