Skip to content

Commit 4842a99

Browse files
committed
doc: 更新获取滑动时间剩余时间逻辑
1 parent 3e217f1 commit 4842a99

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/BootstrapBlazor.Server/Extensions/ICacheEntryExtensions.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ public static string GetExpiration(this ICacheEntry entry)
4747
private static TimeSpan GetSlidingLeftTime(this ICacheEntry entry)
4848
{
4949
var lastAccessed = entry.GetLastAccessed();
50-
return lastAccessed == null ? TimeSpan.Zero : entry.SlidingExpiration!.Value - (DateTime.UtcNow - lastAccessed.Value);
50+
if (lastAccessed == null)
51+
{
52+
return TimeSpan.Zero;
53+
}
54+
55+
var ts = entry.SlidingExpiration!.Value - (DateTime.UtcNow - lastAccessed.Value);
56+
if (ts < TimeSpan.Zero)
57+
{
58+
ts = TimeSpan.Zero;
59+
}
60+
return ts;
5161
}
5262
}

0 commit comments

Comments
 (0)