From c87b059cbdfaced4db2b17f73bc8ff361a4df7a5 Mon Sep 17 00:00:00 2001 From: Memoyu Date: Thu, 12 Oct 2023 10:55:17 +0800 Subject: [PATCH] fix: no check expires when get cache count in memory cache --- src/EasyCaching.InMemory/Internal/InMemoryCaching.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/EasyCaching.InMemory/Internal/InMemoryCaching.cs b/src/EasyCaching.InMemory/Internal/InMemoryCaching.cs index 408f7fa8..3cfe1d27 100644 --- a/src/EasyCaching.InMemory/Internal/InMemoryCaching.cs +++ b/src/EasyCaching.InMemory/Internal/InMemoryCaching.cs @@ -49,8 +49,8 @@ public void Clear(string prefix = "") public int GetCount(string prefix = "") { return string.IsNullOrWhiteSpace(prefix) - ? _memory.Count - : _memory.Count(x => x.Key.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)); + ? _memory.Values.Where(x => x.ExpiresAt > SystemClock.UtcNow).Count() + : _memory.Values.Where(x => x.Key.StartsWith(prefix, StringComparison.OrdinalIgnoreCase) && x.ExpiresAt > SystemClock.UtcNow).Count(); } internal void RemoveExpiredKey(string key)