Click here to Skip to main content
15,885,757 members
Articles / Web Development / ASP.NET

Zeta Enterprise Library

Rate me:
Please Sign up or sign in to vote.
4.97/5 (14 votes)
16 Jan 2010CPOL3 min read 50.2K   2.3K   48  
A small set of general-purpose classes for using in .NET applications (2.0 or higher)
namespace Zeta.EnterpriseLibrary.Caching
{
	#region Using directives.
	// ----------------------------------------------------------------------

	using System;
	using System.Collections.Generic;
	using Properties;
	using System.Diagnostics;

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

	/////////////////////////////////////////////////////////////////////////

	/// <summary>
	/// Controls the treatment of a cached item.
	/// </summary>
	[DebuggerDisplay( @"GroupName = {groupName}" )]
	public class CacheItemInformation
	{
		#region Public properties.
		// ------------------------------------------------------------------

		/// <summary>
		/// Gets or sets the absolute expiration.
		/// </summary>
		/// <value>The absolute expiration.</value>
		public DateTime AbsoluteExpiration
		{
			get
			{
				return absoluteExpiration;
			}
			set
			{
				absoluteExpiration = value;
			}
		}

		/// <summary>
		/// Gets or sets the sliding expiration.
		/// </summary>
		/// <value>The sliding expiration.</value>
		public TimeSpan SlidingExpiration
		{
			get
			{
				return slidingExpiration;
			}
			set
			{
				slidingExpiration = value;
			}
		}

		/// <summary>
		/// When the cache should expire.
		/// </summary>
		/// <value>The expiration mode.</value>
		public CacheExpirationMode ExpirationMode
		{
			get
			{
				if ( absoluteExpiration != NoAbsoluteExpiration )
				{
					return CacheExpirationMode.Absolute;
				}
				else if ( slidingExpiration != NoSlidingExpiration )
				{
					return CacheExpirationMode.Sliding;
				}
				else
				{
					return CacheExpirationMode.Never;
				}
			}
		}

		/// <summary>
		/// Creates a default item.
		/// </summary>
		/// <value>The default.</value>
		public static CacheItemInformation Default
		{
			get
			{
				CacheItemInformation info = new CacheItemInformation();
				return info;
			}
		}

		/// <summary>
		/// If this value is non-empty, this value is used to generate
		/// the key to store in the cache, or to delete from the cache.
		/// If this value is empty, the key is generated from the SQL
		/// query only.
		/// </summary>
		/// <value>The group.</value>
		public CacheItemGroup Group
		{
			get
			{
				return new CacheItemGroup( groupName );
			}
			set
			{
				// Cannot be empty.
				if ( value == null || value.IsEmpty )
				{
					throw new ArgumentException(
						Resources.Str_ZetaLib_Core_Caching_CacheItemInformation_01,
						@"Group" );
				}
				else
				{
					groupName = value.Name;
				}
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public ICacheItemRefreshAction RefreshAction
		{
			get
			{
				return refreshAction;
			}
			set
			{
				refreshAction = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public static readonly DateTime NoAbsoluteExpiration =
			DateTime.MaxValue;

		/// <summary>
		/// 
		/// </summary>
		public static readonly TimeSpan NoSlidingExpiration =
			TimeSpan.Zero;

		/// <summary>
		/// Gets a value indicating whether this instance has expirations.
		/// </summary>
		/// <value>
		/// 	<c>true</c> if this instance has expirations; otherwise, <c>false</c>.
		/// </value>
		public bool HasExpirations
		{
			get
			{
				return expirations != null && expirations.Count > 0;
			}
		}

		/// <summary>
		/// Gets the expirations.
		/// </summary>
		/// <value>The expirations.</value>
		public IList<ICacheItemExpiration> Expirations
		{
			get
			{
				if ( expirations == null )
				{
					expirations = new List<ICacheItemExpiration>();
				}

				return expirations;
			}
		}

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

		#region Private variables.
		// ------------------------------------------------------------------

		/// <summary>
		/// 
		/// </summary>
		private DateTime absoluteExpiration =
			DateTime.Now.Add( TimeSpan.FromMinutes( 20 ) );

		/// <summary>
		/// 
		/// </summary>
		private TimeSpan slidingExpiration =
			TimeSpan.FromMinutes( 20 );

		/// <summary>
		/// 
		/// </summary>
		private string groupName;

		/// <summary>
		/// 
		/// </summary>
		private ICacheItemRefreshAction refreshAction;

		/// <summary>
		/// 
		/// </summary>
		private IList<ICacheItemExpiration> expirations;

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