的MemoryCache总是返回"零"第一到期后 [英] MemoryCache always returns "null" after first expiration

查看:126
本文介绍了的MemoryCache总是返回"零"第一到期后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下问题,我有这样的缓存管理:

I have the following problem, I have this kind of cache management:

public class CacheManager : ICacheManager {

    private readonly ObjectCache cache;

    public CacheManager() {
        this.cache = MemoryCache.Default;
    }

    public void AddItem(string key, object itemToCache, double duration) {
        var end = DateTime.Now.AddSeconds(duration);
        this.cache.Add(key, itemToCache, end);
    }

    public T Get<T>(string key) where T : class {
        try {
            return (T)this.cache[key];
        }
        catch (Exception ex) {
            return null;
        }
    }

    public void Remove(string key) {
        this.cache.Remove(key);
    }
}

其实很简单。

修改我(在这个问题的文字错误修正)

问题:当任何密钥缓存过期,以下所有调用得到回报缓存空的对象。我检查钥匙和是总是正确的。

Problem: When the cache for any key expires, all the following calls to get any object in cache return "null". I check the keys and are always correct.

仅出现该问题的客户端的服务器在我的电脑和我的服务器完美的作品。

The problem occurs only in the client's server in my PC and my server works perfectly.

感谢。

修改II(进步)

当我们重新启动应用程序池在客户的服务器,你的问题就解决了​​几个小时。

When we restart the Application Pool in the customer's server, you problem is solved for a few hours.

有一个特定的应用程序池我们与以下设置网站:

There is a specific Application Pool for our site with the following settings:

管道管理模式:集成
框架:V4.0
启用32位应用程序:真正的

Pipeline Manager mode: Integrated Framework: v4.0 Enable 32-bit Application: True.

其他设置,如默认值。

在我们有2个站点,其中一个服务器启用32位应用程序启用后,如果两者都禁用发生错误,但不知道如果这就是问题所在。

On the server we have 2 sites, one with "Enable 32-bit Application" enabled, if both are disabled the error occurred, but do not know if this is the problem.

修改III(进步)

由于我们没有解决这个问题,我们决定改用的 Httpcontext.Current.Cache ,我们可以解决这个问题。我们需要另一种解决方案,并继续使用的MemoryCache 但没有导致

As we fail to solve the problem, we decided to switch to Httpcontext.Current.Cache, and we could solve the problem. We wanted another solution and continue to use MemoryCache but did not result.

推荐答案

复活一个老问题,但我相信这个问题是由于只固定于ASP.NET 4.5中的错误,但对于早期版本的修补程序。

Resurrecting an old question, but I believe this problem is due to a bug that was only fixed in ASP.NET 4.5, but has a hotfix for earlier versions.

请参阅此线程:<一href=\"http://stackoverflow.com/questions/7422859/memorycache-empty-disposed-in-web-application\">MemoryCache空:被设置后,则返回null

See this thread: MemoryCache Empty : Returns null after being set

这篇关于的MemoryCache总是返回&QUOT;零&QUOT;第一到期后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆