Thursday, March 4, 2010

HttpContext.Current.Cache Vs HttpRuntime.Cache

We normally use the HttpContext.Current.Cache for caching data but internally HttpContext uses HttpRuntime.Cache to do the actual caching. The advantage of using HttpRuntime directly is that it is always available, for example, in Console applications and in Unit tests.

Using HttpRuntime.Cache is simple. Objects can be stored in the cache and are indexed by a string. Along with a key and the object to cache the other important parameter is the expiry time. This parameter sets the time before the object is dropped from the cache.

Happy Coding J

No comments: