For various decisions (which entries to prune, which entries to refresh)
and for debugging, it's useful to track how many hits a cache entry
gets.
This patch adds the basic counting for this; the only tricky aspect
is that we serve DNS entries out of the cache, even in case of a miss,
so we need to compensate for that by subtracting a hit first.
struct cache_entry {
char *key;
+ int hits;
struct cache_data *ipv4;
struct cache_data *ipv6;
};
data->cache_until = entry->ipv4->cache_until;
memcpy(data->data, msg, msg_len);
entry->ipv6 = data;
+ /*
+ * we will get a "hit" when we serve the response
+ * out of the cache
+ */
+ entry->hits--;
+ if (entry->hits < 0)
+ entry->hits = 0;
return 0;
}
}
entry->key = g_strdup(question);
entry->ipv4 = entry->ipv6 = NULL;
+ entry->hits = 0;
if (type == 1)
entry->ipv4 = data;
else
entry->ipv6 = data;
+ /*
+ * compensate for the hit we'll get for serving
+ * the response out of the cache
+ */
+ entry->hits--;
+ if (entry->hits < 0)
+ entry->hits = 0;
+
new_entry = FALSE;
}
else
data = entry->ipv6;
- if (data)
+ if (data) {
ttl_left = data->valid_until - time(0);
+ entry->hits++;
+ }
if (data != NULL && req->protocol == IPPROTO_TCP) {
send_cached_response(req->client_sk, data->data,