Centralized way to delete Cache object in asp.net

I need to keep the old asp.net application and disable all access to the Cache object for debugging purposes. There are hundreds of pages that use structure:

if (Cache["myobject"] != null)
{
   //get data from the cache
   //...
}
else
{
   //go to the DB, load the cache and send it to the client
}

I know that I need to reorganize this code, but so far you know some simple and centralized way to let (or disable) the Cache object?

+3
source share
3 answers

, , , , privateBytesLimit 1 privateBytesPollTime 00:00:01. , ASP.NET , . .

+3

, , .

+3

If you just want to clear the cache once, you can use this:

   foreach ( System.Collections.DictionaryEntry entry in HttpContext.Current.Cache )
        HttpContext.Current.Cache.Remove( entry.Key as String );

Otherwise, @Anton Gogolev's solution is great for preventing new entries.

+2
source

Source: https://habr.com/ru/post/1719522/


All Articles