}
const CacheValue& value = it->second;
- if (value.validity < now) {
+ if (value.validity <= now) {
if ((now - value.validity) >= static_cast<time_t>(allowExpired)) {
d_misses++;
return false;
/* Remove expired entries, until the cache has at most
upTo entries in it.
*/
-void DNSDistPacketCache::purgeExpired(size_t upTo)
+size_t DNSDistPacketCache::purgeExpired(size_t upTo)
{
+ size_t removed = 0;
uint64_t size = getSize();
if (size == 0 || upTo >= size) {
- return;
+ return removed;
}
size_t toRemove = size - upTo;
for(auto it = map.begin(); toRemove > 0 && it != map.end(); ) {
const CacheValue& value = it->second;
- if (value.validity < now) {
+ if (value.validity <= now) {
it = map.erase(it);
--toRemove;
d_shards[shardIndex].d_entriesCount--;
+ ++removed;
} else {
++it;
}
scannedMaps++;
}
while (toRemove > 0 && scannedMaps < d_shardCount);
+
+ return removed;
}
/* Remove all entries, keeping only upTo
entries in the cache */
-void DNSDistPacketCache::expunge(size_t upTo)
+size_t DNSDistPacketCache::expunge(size_t upTo)
{
+ size_t removed = 0;
const uint64_t size = getSize();
if (upTo >= size) {
- return;
+ return removed;
}
size_t toRemove = size - upTo;
- size_t removed = 0;
for (uint32_t shardIndex = 0; shardIndex < d_shardCount; shardIndex++) {
WriteLock w(&d_shards.at(shardIndex).d_lock);
d_shards[shardIndex].d_entriesCount = 0;
}
}
+
+ return removed;
}
-void DNSDistPacketCache::expungeByName(const DNSName& name, uint16_t qtype, bool suffixMatch)
+size_t DNSDistPacketCache::expungeByName(const DNSName& name, uint16_t qtype, bool suffixMatch)
{
+ size_t removed = 0;
+
for (uint32_t shardIndex = 0; shardIndex < d_shardCount; shardIndex++) {
WriteLock w(&d_shards.at(shardIndex).d_lock);
auto& map = d_shards[shardIndex].d_map;
if ((value.qname == name || (suffixMatch && value.qname.isPartOf(name))) && (qtype == QType::ANY || qtype == value.qtype)) {
it = map.erase(it);
d_shards[shardIndex].d_entriesCount--;
+ ++removed;
} else {
++it;
}
}
}
+
+ return removed;
}
bool DNSDistPacketCache::isFull()