From: Willy Tarreau Date: Wed, 13 Apr 2022 09:21:39 +0000 (+0200) Subject: BUG/MINOR: cache: do not display expired entries in "show cache" X-Git-Tag: v2.6-dev6~111 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f1de1b51cab49f654938524a515cf26ac2db0bf5;p=thirdparty%2Fhaproxy.git 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 0f90af9843..1aa1103a6b 100644 --- a/src/cache.c +++ b/src/cache.c @@ -2599,12 +2599,21 @@ static int cli_io_handler_show_cache(struct appctx *appctx) } 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));