【发布时间】:2014-08-12 07:31:19
【问题描述】:
Environment:
asp.net mvc
iis
我围绕 memorycache 创建了一个包装器和具体类,我在它的 constrcutor 中设置了 memoryCache
public class AbijMemoryCache : IAbijMemoryCache
{
private readonly MemoryCache _cache;
public AbijMemoryCache()
{
if (_cache == null)
{
_cache = MemoryCache.Default;
}
}
}
然后在 unity 中只获取一个我使用过的内存缓存实例 ContainerControlledLifetimeManager
container.RegisterType<IAbijMemoryCache, AbijMemoryCache>(new ContainerControlledLifetimeManager());
我使用以下代码在我的 homeController 中设置缓存
var policy = new CacheItemPolicy();
_cache.Set(key, value, policy);
但在上传到 iis 缓存后有时会变空。
检查
_cache.Get(key) **`it gets null`**
为什么它会为空? 我该怎么办?
【问题讨论】:
标签: c# asp.net-mvc iis memorycache