0

I'm using simple ObjectCache and MemoryCache class to implement cache.

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];
        }

I want to add method to check empty cache but not based on any key only wanted to check whether whole cache is empty or not how can I do so ?

Neo
  • 15,491
  • 59
  • 215
  • 405
  • [GetCount()](https://msdn.microsoft.com/en-us/library/system.runtime.caching.objectcache.getcount(v=vs.110).aspx) == 0? – SwDevMan81 Mar 06 '15 at 16:46

2 Answers2

2

Use the GetCount() method.

https://msdn.microsoft.com/en-us/library/system.runtime.caching.memorycache.getcount(v=vs.110).aspx

var cache = MemoryCache.Default;

bool isEmpty = cache.GetCount() == 0;
EkoostikMartin
  • 6,831
  • 2
  • 33
  • 62
2

You could try the GetCount() method to see how many items are in the MemoryCache.

Paul Griffin
  • 2,416
  • 15
  • 19