0

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
            }
        }
renuka
  • 549
  • 2
  • 5
  • 11
  • I feel as if I am missing the bigger picture here, however, one suggestion would be to store the keys in an http application level object. You need to iterate like done above and store the keys _once_. Subsequently, you can refer to the application object to retrieve those keys. – deostroll Jun 24 '14 at 05:27

1 Answers1

1

You can try like this:

int i = 0;
while (i < Cache.Keys.Length){
   if (Cache.Keys(i).Contains(keyName){
      //Code
   } 
   else{
      i ++;
   }
}
Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
  • isn't there any method without looping through? – renuka Jun 24 '14 at 05:01
  • @renuka:- AFAIK there is no such method. The best I can think of if you want to access it faster is you can store the data for the most searched keywords in a table for faster access. You can also create a job to refresh the table at regular intervals, based on some fairly easy algorithms – Rahul Tripathi Jun 24 '14 at 05:04