【发布时间】:2018-09-12 21:06:24
【问题描述】:
我试图在我的 .net mvc 应用程序中缓存一个字符串 24 小时。我无法找到让缓存过期的方法。目前我使用
设置缓存System.Runtime.Caching.MemoryCache.Default["activeKey"] = "success";
我通过调用来使用缓存
var activeKey = System.Runtime.Caching.MemoryCache.Default["activeKey"];
if (activeKey != null && (string) activeKey == "success")
{
return true;
}
但是,我不确定从这里到缓存的位置。我找到了有关滑动和绝对缓存的文档,但不确定该怎么做。
【问题讨论】:
-
class HackItCacheItem { public DateTime Created {get;set;} public string Value {get;set;} }if DateTime.Now - Created > TimeSpan.FromDays(1) ... -
我认为你需要使用
Add(),它对 CacheItemPolicy 有一个重载
标签: c# asp.net-mvc caching