AppFabric 缓存突然过期

发布于 2024-12-11 07:31:39 字数 2864 浏览 0 评论 0原文

我目前正在测试 AppFabric 缓存,但我的缓存遇到了一个奇怪的问题。尽管我说他需要缓存一个简单的对象3分钟,但他只缓存了大约3秒。

我的缓存设置如下:

PS C:> Get-CacheConfig 默认值 缓存名称:默认 生存时间:100 分钟 缓存类型:分区 次要 : 0 是否可过期:True 逐出类型:LRU NotificationsEnabled : False

我使用以下 3 个 commandlet 构建了此缓存:

Use-CacheCluster 
Start-CacheCluster
Grant-CacheAllowedClientAccount <myAccount>

​​ 之后我尝试运行以下程序 (program.cs):

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Press any key to continue, Q to quit");
        while (Console.ReadKey() != new ConsoleKeyInfo('q', ConsoleKey.Q, false, false, false))
        {
            DoStuff();
        }
    }

    static void DoStuff()
    {
        Person p = null;
        DataCacheItem cacheItem = CacheUtility.CurrentCache.GetCacheItem("jebas");
        if (cacheItem != null)
        {
            Console.WriteLine("V - Got my stuff from cache");
            p = (Person)cacheItem.Value;
        }

        if (p == null)
        {
            Console.WriteLine("! - I just did an expensive call");
            p = GetPerson();
            CacheUtility.CurrentCache.Add("jebas", p, new TimeSpan(0, 30, 0));
        }
    }

    private static Person GetPerson()
    {
        return new Person() { FirstName = "Jeroen", LastName = "Van Bastelaere", Id = Guid.NewGuid() };
    }
}

CacheUtility 类:

sealed class CacheUtility
{
    private static DataCacheFactory _factory;
    private static DataCache _cache;
    private static readonly object _lock = new object();

    CacheUtility() { }

    public static DataCache CurrentCache
    {
        get
        {
            lock (_lock)
            {
                if (_cache == null)
                {
                    List<DataCacheServerEndpoint> servers = new List<DataCacheServerEndpoint>();
                    servers.Add(new DataCacheServerEndpoint("demo2010a", 22233));
                    DataCacheFactoryConfiguration config = new DataCacheFactoryConfiguration()
                    {
                        Servers = servers
                    };
                    _factory = new DataCacheFactory(config);
                    _cache = _factory.GetDefaultCache();
                }
                return _cache;
            }
        }
    }
}

使用此程序,我只需运行它并按随机键一段时间: 大多数有时它会说“我从缓存中获取它”,但每 3 秒它就会执行一次昂贵的调用。 当我检查 Get-CacheStatistics 默认值时,当他错过缓存时,他会看到:

PS C:> Get-CacheStatistics 默认

大小:0 商品数量:0 区域数量:1 请求数:1543 MissCount:75

当它在缓存中时,它给我这个:

大小:566 商品数量:1 区域数量:1 请求数:1553 MissCount : 77

使用 perfmon 我能够知道我的对象被逐出,因为当我运行程序时计数器 Total Evicted Objects 会上升(并且它突然不再在缓存中)。

我不知道为什么它被逐出,这是我目前正在缓存的唯一对象,并且服务器还有足够的内存(4GB+)

任何人都可以帮助我让我的对象缓存我要求的 30 分钟它缓存而不是3秒?

非常感谢帮助。 :-)

提前致谢,

杰罗恩

I'm currently testing AppFabric caching, but I'm having a strange problem with my caching. Even though I say he needs to cache a simple object for 3 minutes, he only caches it for approximately 3 seconds.

The settings for my cache are as follows:

PS C:> Get-CacheConfig default
CacheName : default
TimeToLive : 100 mins
CacheType : Partitioned
Secondaries : 0
IsExpirable : True
EvictionType : LRU
NotificationsEnabled : False

I built this cache using the following 3 commandlets:

Use-CacheCluster 
Start-CacheCluster
Grant-CacheAllowedClientAccount <myAccount>

Afterwards I try to run the following program (program.cs):

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Press any key to continue, Q to quit");
        while (Console.ReadKey() != new ConsoleKeyInfo('q', ConsoleKey.Q, false, false, false))
        {
            DoStuff();
        }
    }

    static void DoStuff()
    {
        Person p = null;
        DataCacheItem cacheItem = CacheUtility.CurrentCache.GetCacheItem("jebas");
        if (cacheItem != null)
        {
            Console.WriteLine("V - Got my stuff from cache");
            p = (Person)cacheItem.Value;
        }

        if (p == null)
        {
            Console.WriteLine("! - I just did an expensive call");
            p = GetPerson();
            CacheUtility.CurrentCache.Add("jebas", p, new TimeSpan(0, 30, 0));
        }
    }

    private static Person GetPerson()
    {
        return new Person() { FirstName = "Jeroen", LastName = "Van Bastelaere", Id = Guid.NewGuid() };
    }
}

CacheUtility class:

sealed class CacheUtility
{
    private static DataCacheFactory _factory;
    private static DataCache _cache;
    private static readonly object _lock = new object();

    CacheUtility() { }

    public static DataCache CurrentCache
    {
        get
        {
            lock (_lock)
            {
                if (_cache == null)
                {
                    List<DataCacheServerEndpoint> servers = new List<DataCacheServerEndpoint>();
                    servers.Add(new DataCacheServerEndpoint("demo2010a", 22233));
                    DataCacheFactoryConfiguration config = new DataCacheFactoryConfiguration()
                    {
                        Servers = servers
                    };
                    _factory = new DataCacheFactory(config);
                    _cache = _factory.GetDefaultCache();
                }
                return _cache;
            }
        }
    }
}

Using this program, I just run it and press a random key for an amount of time: Most of the time it says "I got it from cache", but once in every 3 seconds it does the expensive call.
When I check with Get-CacheStatistics default when he misses the cache he has this:

PS C:> Get-CacheStatistics default

Size : 0
ItemCount : 0
RegionCount : 1
RequestCount : 1543
MissCount : 75

When it is in cache it gives me this:

Size : 566
ItemCount : 1
RegionCount : 1
RequestCount : 1553
MissCount : 77

Using perfmon I was able to tell that my object gets evicted, because the counter Total Evicted Objects rises when I run my program (and it's suddenly not in cache anymore).

I have no idea why it is being evicted though, that's the only object I'm caching at the moment and the server has got plenty of memory left (4GB+)

Can anybody help me to get my object cached for the 30 minutes that I ask it to cache instead of 3 seconds?

Help is very appreciated. :-)

Thanks in advance,

Jeroen

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暮光沉寂 2024-12-18 07:31:39

当 Windows Server AppFabric 缓存上的物理内存变低时
主机,缓存主机可以进入一种称为节流的状态。缓存
集群不会将数据写入驻留在受限制的任何缓存中
缓存主机直到可用物理内存增加才能解决
节流状态。

http://msdn.microsoft.com/en-us/library/ff921030.aspx

;)

When physical memory becomes low on a Windows Server AppFabric cache
host, the cache host can enter a state called throttling. The cache
cluster will not write data to any cache that resides on a throttled
cache host until the available physical memory increases to resolve
the throttled state.

http://msdn.microsoft.com/en-us/library/ff921030.aspx

;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文