Get cache elements with key

295 Views Asked by At

In ASP.NET, we have the

IDictionaryEnumerator enumerator = Cache.GetEnumerator();

to get the elements of all cache objecs.

Do we have any method to get the cache objects that start with particular string. Something like

IDictionaryEnumerator enumerator = Cache.GetEnumerator("%key%");

instead of

while (enumerator.MoveNext())
        {
            if (enumerator.Key.ToString().ToLower().StartsWith("key"))
            {
                //code
            }
        }
1

There are 1 best solutions below

2
On

You can try like this:

int i = 0;
while (i < Cache.Keys.Length){
   if (Cache.Keys(i).Contains(keyName){
      //Code
   } 
   else{
      i ++;
   }
}