修复MemoryCacheService使用Add方法添加缓存默认是滑动过期的bug(by @不容易ljg)

This commit is contained in:
jxx
2025-07-25 14:26:34 +08:00
parent 9b7476ddb0
commit a3a5ddb8d6
2 changed files with 24 additions and 2 deletions
@@ -52,11 +52,22 @@ namespace VOL.Core.CacheManager
{
if (expireSeconds != -1)
{
_cache.Set(key,
if (isSliding)
{
_cache.Set(key,
value,
new MemoryCacheEntryOptions()
.SetSlidingExpiration(new TimeSpan(0, 0, expireSeconds))
);
}
else
{
_cache.Set(key,
value,
new MemoryCacheEntryOptions()
.SetAbsoluteExpiration(new TimeSpan(0, 0, expireSeconds))
);
}
}
else
{
@@ -52,11 +52,22 @@ namespace VOL.Core.CacheManager
{
if (expireSeconds != -1)
{
_cache.Set(key,
if (isSliding)
{
_cache.Set(key,
value,
new MemoryCacheEntryOptions()
.SetSlidingExpiration(new TimeSpan(0, 0, expireSeconds))
);
}
else
{
_cache.Set(key,
value,
new MemoryCacheEntryOptions()
.SetAbsoluteExpiration(new TimeSpan(0, 0, expireSeconds))
);
}
}
else
{