am 73a6566d
: Merge "Remove expired dns cache entries before removing oldest"
* commit '73a6566da337db50cfc73c369d774ac1905a30c2': Remove expired dns cache entries before removing oldest
This commit is contained in:
commit
53daf4757d
1 changed files with 25 additions and 1 deletions
|
@ -1433,6 +1433,27 @@ _cache_remove_oldest( Cache* cache )
|
|||
_cache_remove_p(cache, lookup);
|
||||
}
|
||||
|
||||
/* Remove all expired entries from the hash table.
|
||||
*/
|
||||
static void _cache_remove_expired(Cache* cache) {
|
||||
Entry* e;
|
||||
time_t now = _time_now();
|
||||
|
||||
for (e = cache->mru_list.mru_next; e != &cache->mru_list;) {
|
||||
// Entry is old, remove
|
||||
if (now >= e->expires) {
|
||||
Entry** lookup = _cache_lookup_p(cache, e);
|
||||
if (*lookup == NULL) { /* should not happen */
|
||||
XLOG("%s: ENTRY NOT IN HTABLE ?", __FUNCTION__);
|
||||
return;
|
||||
}
|
||||
e = e->mru_next;
|
||||
_cache_remove_p(cache, lookup);
|
||||
} else {
|
||||
e = e->mru_next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ResolvCacheStatus
|
||||
_resolv_cache_lookup( struct resolv_cache* cache,
|
||||
|
@ -1547,7 +1568,10 @@ _resolv_cache_add( struct resolv_cache* cache,
|
|||
}
|
||||
|
||||
if (cache->num_entries >= cache->max_entries) {
|
||||
_cache_remove_oldest(cache);
|
||||
_cache_remove_expired(cache);
|
||||
if (cache->num_entries >= cache->max_entries) {
|
||||
_cache_remove_oldest(cache);
|
||||
}
|
||||
/* need to lookup again */
|
||||
lookup = _cache_lookup_p(cache, key);
|
||||
e = *lookup;
|
||||
|
|
Loading…
Reference in a new issue