Monday, February 16, 2009

Caching with HttpRuntime.Cache

  string someObject = "FooBar";

  //Cache the value
  HttpRuntime.Cache.Add("somekey", someObject, null,
    DateTime.UtcNow.AddMinutes(1.0),
    System.Web.Caching.Cache.NoSlidingExpiration,
    System.Web.Caching.CacheItemPriority.Normal, null);

  someObject = null;      

  //Access the cached value
  someObject = (string) HttpRuntime.Cache.Get( "somekey" );