namespace ZetaLib.Web.Caching { #region Using directives. // ---------------------------------------------------------------------- using System; using System.Collections; using System.Collections.Specialized; using System.Web; using System.Web.Caching; using System.Collections.Generic; using ZetaLib.Core.Caching; // ---------------------------------------------------------------------- #endregion ///////////////////////////////////////////////////////////////////////// /// <summary> /// Caching on a per-request-basis. /// See http://msdn.microsoft.com/msdnmag/issues/05/01/ASPNETPerformance/. /// </summary> public class PerRequestWebCache { #region Public properties. // ------------------------------------------------------------------ /// <summary> /// Best practice, see C# MSDN documentation of the "lock" keyword. /// </summary> private object thisLock = new object(); /// <summary> /// Read from and write to the cache. /// </summary> /// <value></value> public object this[string key] { get { HttpContext cache = HttpContext.Current; if ( cache != null ) { lock ( thisLock ) { return cache.Items[key]; } } else { return null; } } set { HttpContext cache = HttpContext.Current; if ( cache != null ) { lock ( thisLock ) { cache.Items[key] = value; } } } } // ------------------------------------------------------------------ #endregion } ///////////////////////////////////////////////////////////////////////// }
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)