BUG/MINOR: cache: do not display expired entries in "show cache"
It was mentioned in issue #12 that expired entries would appear with a
negative expire delay in "show cache". Instead of listing them, let's
just evict them.
This could be backported to all versions since this was reported on
1.8 already.
diff --git a/src/cache.c b/src/cache.c
index 0f90af9..1aa1103 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -2599,12 +2599,21 @@
}
entry = container_of(node, struct cache_entry, eb);
- chunk_printf(&trash, "%p hash:%u vary:0x", entry, read_u32(entry->hash));
- for (i = 0; i < HTTP_CACHE_SEC_KEY_LEN; ++i)
- chunk_appendf(&trash, "%02x", (unsigned char)entry->secondary_key[i]);
- chunk_appendf(&trash, " size:%u (%u blocks), refcount:%u, expire:%d\n", block_ptr(entry)->len, block_ptr(entry)->block_count, block_ptr(entry)->refcount, entry->expire - (int)now.tv_sec);
-
next_key = node->key + 1;
+
+ if (entry->expire > now.tv_sec) {
+ chunk_printf(&trash, "%p hash:%u vary:0x", entry, read_u32(entry->hash));
+ for (i = 0; i < HTTP_CACHE_SEC_KEY_LEN; ++i)
+ chunk_appendf(&trash, "%02x", (unsigned char)entry->secondary_key[i]);
+ chunk_appendf(&trash, " size:%u (%u blocks), refcount:%u, expire:%d\n",
+ block_ptr(entry)->len, block_ptr(entry)->block_count,
+ block_ptr(entry)->refcount, entry->expire - (int)now.tv_sec);
+ } else {
+ /* time to remove that one */
+ delete_entry(entry);
+ entry->eb.key = 0;
+ }
+
appctx->ctx.cli.i0 = next_key;
shctx_unlock(shctx_ptr(cache));