![](/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.