Skip to content

Commit 06e0a47

Browse files
committed
Simplified cache handling
1 parent fea2585 commit 06e0a47

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/LinkDotNet.Blog.Web/Features/Components/ShortBlogPost.razor

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@
6666
protected override void OnInitialized()
6767
{
6868
var key = "reading-time-" + BlogPost.Id;
69-
if (!MemoryCache.TryGetValue(key, out readingTime))
69+
readingTime = MemoryCache.GetOrCreate(key, entry =>
7070
{
71-
readingTime = ReadingTimeCalculator.CalculateReadingTime(BlogPost.Content);
72-
MemoryCache.Set(key, readingTime, TimeSpan.FromHours(1));
73-
}
71+
entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(1);
72+
return ReadingTimeCalculator.CalculateReadingTime(BlogPost.Content);
73+
});
7474
}
7575
}

0 commit comments

Comments
 (0)