Click here to Skip to main content
15,896,269 members
Articles / Programming Languages / C#

Zeta .NET Base Libraries

Rate me:
Please Sign up or sign in to vote.
4.41/5 (44 votes)
30 Mar 2007CPOL3 min read 152K   2.4K   147  
A small set of general-purpose classes for using in .NET applications
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>
	/// Provide an extended version of System.Web.Caching.Cache.
	/// </summary>
	public class WebCacheManager :
		CacheManager
	{
		#region Public methods and properties.
		// ------------------------------------------------------------------

		/// <summary>
		/// Caching items on a per-request-basis.
		/// </summary>
		/// <value>The per request.</value>
		public PerRequestWebCache PerRequest
		{
			get
			{
				lock ( thisLock )
				{
					if ( perRequest == null )
					{
						perRequest = new PerRequestWebCache();
					}

					return perRequest;
				}
			}
		}

		/// <summary>
		/// Caching on a per-user-session-basis.
		/// </summary>
		/// <value>The per session.</value>
		public PerSessionWebCache PerSession
		{
			get
			{
				lock ( thisLock )
				{
					if ( perSession == null )
					{
						perSession = new PerSessionWebCache();
					}

					return perSession;
				}
			}
		}

		/// <summary>
		/// Caching on a per-application-basis, shared by all users.
		/// </summary>
		/// <value>The per application.</value>
		public PerApplicationWebCache PerApplication
		{
			get
			{
				lock ( thisLock )
				{
					if ( perApplication == null )
					{
						perApplication = new PerApplicationWebCache();
					}

					return perApplication;
				}
			}
		}

		/// <summary>
		/// Empties the complete cache.
		/// </summary>
		public override void RemoveAll()
		{
			base.RemoveAll();

			PerSession.RemoveAll();
			PerApplication.RemoveAll();
		}

		/// <summary>
		/// Removes all items from the cache with
		/// a certain prefix in the key.
		/// </summary>
		/// <param name="group">The group.</param>
		public override void RemoveAll(
			CacheItemGroup group )
		{
			base.RemoveAll( group );

			PerSession.RemoveAll( group );
			PerApplication.RemoveAll( group );
		}

		// ------------------------------------------------------------------
		#endregion

		#region Private helper.
		// ------------------------------------------------------------------

		/// <summary>
		/// Best practice, see C# MSDN documentation of the "lock" keyword.
		/// </summary>
		private object thisLock = new object();

		/// <summary>
		/// Storing the other cache references.
		/// </summary>
		private PerRequestWebCache perRequest = null;
		private PerSessionWebCache perSession = null;
		private PerApplicationWebCache perApplication = null;

		// ------------------------------------------------------------------
		#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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Chief Technology Officer Zeta Software GmbH
Germany Germany
Uwe does programming since 1989 with experiences in Assembler, C++, MFC and lots of web- and database stuff and now uses ASP.NET and C# extensively, too. He has also teached programming to students at the local university.

➡️ Give me a tip 🙂

In his free time, he does climbing, running and mountain biking. In 2012 he became a father of a cute boy and in 2014 of an awesome girl.

Some cool, free software from us:

Windows 10 Ereignisanzeige  
German Developer Community  
Free Test Management Software - Intuitive, competitive, Test Plans.  
Homepage erstellen - Intuitive, very easy to use.  
Offline-Homepage-Baukasten

Comments and Discussions