Environment:
asp.net mvc
iis
我已经围绕 memorycache 创建了一个包装器和具体类,我在它的constrcutor中设置了 memoryCache
public class AbijMemoryCache : IAbijMemoryCache
{
private readonly MemoryCache _cache;
public AbijMemoryCache()
{
if (_cache == null)
{
_cache = MemoryCache.Default;
}
}
}
然后统一获取内存缓存的一个实例,我使用了ContainerControlledLifetimeManager
container.RegisterType<IAbijMemoryCache, AbijMemoryCache>(new ContainerControlledLifetimeManager());
我使用以下代码在我的 homeController 中设置缓存
var policy = new CacheItemPolicy();
_cache.Set(key, value, policy);
但是在将其上传到 iis 缓存后有时会变空。
检查
_cache.Get(key) **`it gets null`**
为什么它会为空?我该怎么办?