AppFabric中获得命名的缓存对象计数 [英] AppFabric get named cache object count
问题描述
我有一个名为缓存,只是想返回(编程)的对象计数
I have a named cache and simply want to return (programmatically) its object count.
我有一个数据高速缓存对象:
缓存= factory.GetCache (cacheName);
I have a DataCache object: cache = factory.GetCache("cacheName");
我目前正在尝试以下:
cache.GetObjectsInRegion(cacheName)计数();
I'm currently trying the following: cache.GetObjectsInRegion("cacheName").Count();
我意识到,一个地区比命名的缓存不同,但我没有看到任何其他的方法,让我实现这一目标(虽然我敢肯定有)。 ?有什么想法
I realize that a region is different than a named cache, but I don't see any other methods that would allow me to achieve this (although I'm sure there are). Any thoughts?
推荐答案
这是没有那么简单,你可能已经预期 - 但它做的,能够
This isn't as straightforward as you might have expected - but it is do-able.
当一个对象被加入到的AppFabric缓存,它进入一个区域,是否指定了区域或没有。当创建一个高速缓存,一套默认的区域获得创建(其中1024对我的试验台, Default_Region_0000
, Default_Region_0001
等),并作为项目被添加到高速缓存有,我假定,一些算法,用于确定它们进入区域。
When an object is added to an AppFabric cache, it goes into a region, whether you specify the region or not. When a cache is created, a set of default regions get created (1024 of them on my test rig, Default_Region_0000
, Default_Region_0001
and so on), and as items are added to the cache there is, I assume, some algorithm that determines which of the regions they go into.
因此,要找到名为区域之外的对象的高速缓存中的总数,则需要运行GetObjectsInRegion为默认的区域中的每一个:
So, to find the total number of objects in the cache outside of named regions, you need to run GetObjectsInRegion for every one of the default regions:
int totalItemCount = 0;
foreach (string regionName in cache.GetSystemRegions())
{
totalItemCount += cache.GetObjectsInRegion(regionName).Count();
}
考虑到这些1024区域的复杂性,我觉得你可以做一个令人信服的理由每个对象应该是在一个名为区域:有效有没有成本,这样做,并且它变得更容易,看看有多少对象是在缓存中潜在的好处。如果这对你是一个共同的要求,你也可以想想使得对数据高速缓存类此的扩展方法。
Given the complexity of these 1024 regions, I think you could make a convincing case that every object should be in a named region: there's effectively no cost for doing so, and a potential benefit in that it becomes easier to see how many objects are in the cache. If this is a common requirement for you, you could also think about making this an extension method on the DataCache class.
这篇关于AppFabric中获得命名的缓存对象计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!