![](/img/trans.png)
[英]Everytime u connect to an ASP.net application is a new Thread created?
[英]Using memorycache in asp.net mvc application it gets created everytime
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`**
为什么它为空? 我该怎么办?
我发现MemoryCache通过引用工作,因此如果您确实将一个对象分配给memoryCache,则将通过刷新
_cache.Set(key, value, policy); //value should not be an object.
您可以在缓存值之前使用序列化,以便像
var cloneValue = SerializationCloner.DeepFieldClone(value);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.