ASP.Net的AppFabric缓存缺失冲洗/清除和计数/ getCount方法可? [英] ASP.Net AppFabric Cache missing Flush/Clear and Count/GetCount methods?

查看:223
本文介绍了ASP.Net的AppFabric缓存缺失冲洗/清除和计数/ getCount方法可?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用EntLib的解决方案转换为使用AppFabric缓存。通过几扩展方法的帮助,这是一个相当无痛苦的过程。

I am trying to convert a solution using EntLib into using AppFabric caching. By help of a few extension methods this is a fairly pain-free process.

扩展方法我用:

public static bool Contains(this DataCache dataCache, string key)
{
    return dataCache.Get(key) != null;
}

public static object GetData(this DataCache dataCache, string key)
{
    return dataCache.Get(key);
}

但也有EntLib的两个特点,我觉得很难转换。即计数(计数数缓存键)和刷新(从缓存中删除所有数据)。双方可以解决,如果我能在高速缓存中循环的关键。

But there are two features of EntLib I find difficult to convert. Namely "Count" (counting number of keys in cache) and "Flush" (removing all data from cache). Both could be solved if I could iterate the keys in cache.

有一个名为 ClearRegion(串区域)的方法,但这需要我就全部搞定/认沽/添加的方法我用指定的区域名称,这将需要一些手动容易出错的工作。

There is a method called ClearRegion(string region), but that required me to specify a region name on all Get/Put/Add-methods I use, which would require some manual error-prone work.

有没有办法让在高速缓存中的密钥列表?

有没有我可以使用默认的区域名称?

我怎样才能刷新缓存的时候我没有用一个区域名称?

Is there any way to get a list of keys in cache?
Is there a default region name I can use?
How can I flush the cache when I haven't used a region name?

推荐答案

请参阅my为previous答案我的炒作的作为缓存的内部工作原理,当你不指定区域,以及如何可以得到不在一个对象的个数命名的区域。

See my previous answer for my speculation as to how the cache works internally when you don't specify a region, and how you can get the count of objects that aren't in a named region.

我们可以使用相同的技术建立一个Flush方法:

We can build a Flush method using the same technique:

public void Flush (this DataCache cache)
{
    foreach (string regionName in cache.GetSystemRegions()) 
    {     
        cache.ClearRegion(regionName) 
    } 
}

正如我说有,我想叫区域是的可能的要走的路 - 这在我看来,使用它们解决更多的问题比它创建

As I said there, I think named regions are probably the way to go - it seems to me that using them solves more problems than it creates.

这篇关于ASP.Net的AppFabric缓存缺失冲洗/清除和计数/ getCount方法可?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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