C# 使用MemoryCache类检查空缓存的最佳方法是什么?
我使用简单的C# 使用MemoryCache类检查空缓存的最佳方法是什么?,c#,.net,caching,memorycache,asp.net-caching,C#,.net,Caching,Memorycache,Asp.net Caching,我使用简单的ObjectCache和MemoryCache类来实现缓存 public class MemoryCacheManager { protected ObjectCache Cache { get { return MemoryCache.Default; } } /// <summary>
ObjectCache
和MemoryCache
类来实现缓存
public class MemoryCacheManager
{
protected ObjectCache Cache
{
get
{
return MemoryCache.Default;
}
}
/// <summary>
/// Gets or sets the value associated with the specified key.
public virtual T Get<T>(string key)
{
return (T)Cache[key];
}
公共类MemoryCacheManager
{
受保护的对象缓存
{
得到
{
返回MemoryCache.Default;
}
}
///
///获取或设置与指定键关联的值。
公共虚拟T Get(字符串键)
{
返回(T)缓存[键];
}
我想添加方法来检查空缓存,但不基于任何键
只想检查整个缓存是否为空,我该怎么做
使用GetCount()
方法
使用GetCount()
方法
您可以尝试该方法查看内存缓存中有多少项
您可以尝试该方法查看内存缓存中有多少项
==0?==0?
var cache = MemoryCache.Default;
bool isEmpty = cache.GetCount() == 0;