ASP.net C# Code Snippets

Using Microsoft Enterprise Library to Cache Data

  1. Using Dependant Cache in ASP.net

         Cache.Insert("navHTML",  //name of the cache item
                      oSB.ToString(), //what your cacheing
                      new CacheDependency(Server.MapPath("~/web.sitemap")), //the file that would cause cache to updated when changed
                      DateTime.UtcNow.AddMinutes(15), //always refresh after 15 minutes
                      System.Web.Caching.Cache.NoSlidingExpiration); //don't base the cache off last accessed time  
                      
           String navHTML = (String)Cache["navHTML"]; //get the string out of cache