Skip to content

Commit 4749b09

Browse files
committed
refactor: 增加默认缓存策略
1 parent 38f82ca commit 4749b09

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/BootstrapBlazor/Services/CacheManager.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,13 @@ public CacheManager(IServiceProvider provider, IMemoryCache memoryCache)
4646
/// </summary>
4747
public TItem GetOrCreate<TItem>(object key, Func<ICacheEntry, TItem> factory) => Cache.GetOrCreate(key, entry =>
4848
{
49-
if (key is not string)
49+
var item = factory(entry);
50+
51+
if (entry.SlidingExpiration == null && entry.AbsoluteExpiration == null && entry.Priority != CacheItemPriority.NeverRemove)
5052
{
5153
entry.SetSlidingExpiration(TimeSpan.FromMinutes(5));
5254
}
53-
return factory(entry);
55+
return item;
5456
})!;
5557

5658
/// <summary>

0 commit comments

Comments
 (0)