Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Caching
In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv4807/Caching
Modified Files:
AbstractCache.cs BaseCacheAttribute.cs ICache.cs
NonExpiringCache.cs
Removed Files:
CachePriority.cs
Log Message:
SPRNET-683, SPRNET-712
Index: AbstractCache.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Caching/AbstractCache.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** AbstractCache.cs 16 Feb 2007 01:59:31 -0000 1.3
--- AbstractCache.cs 24 Aug 2007 22:43:55 -0000 1.4
***************
*** 32,39 ****
public abstract class AbstractCache : ICache
{
/// <summary>
/// Gets the number of items in the cache.
/// </summary>
! public abstract int Count { get; }
/// <summary>
--- 32,72 ----
public abstract class AbstractCache : ICache
{
+ private bool _enforceTimeToLive = false;
+ private TimeSpan _timeToLive = TimeSpan.Zero;
+
+ /// <summary>
+ /// Gets/Set the Default time-to-live (TTL) for items inserted into this cache.
+ /// Used by <see cref="Insert(object,object)"/>
+ /// </summary>
+ public TimeSpan TimeToLive
+ {
+ get { return _timeToLive; }
+ set { _timeToLive = value; }
+ }
+
+ /// <summary>
+ /// Gets/Sets a value, whether the this cache instance's <see cref="TimeToLive"/>
+ /// shall be applied to all items, regardless of their individual TTL
+ /// when <see cref="Insert(object,object,TimeSpan"/> is called.
+ /// </summary>
+ public bool EnforceTimeToLive
+ {
+ get { return _enforceTimeToLive; }
+ set { _enforceTimeToLive = value; }
+ }
+
/// <summary>
/// Gets the number of items in the cache.
/// </summary>
! /// <remarks>
! /// May be overridden by subclasses for cache-specific efficient implementation.
! /// </remarks>
! public virtual int Count
! {
! get
! {
! return Keys.Count;
! }
! }
/// <summary>
***************
*** 90,95 ****
/// </summary>
/// <remarks>
! /// Items inserted using this method have no expiration time
! /// and default cache priority.
/// </remarks>
/// <param name="key">
--- 123,127 ----
/// </summary>
/// <remarks>
! /// Items inserted using this method use the default
/// </remarks>
/// <param name="key">
***************
*** 101,105 ****
public virtual void Insert(object key, object value)
{
! Insert(key, value, 0, false, CachePriority.Default);
}
--- 133,137 ----
public virtual void Insert(object key, object value)
{
! Insert(key, value, TimeToLive);
}
***************
*** 108,112 ****
/// </summary>
/// <remarks>
! /// Items inserted using this method have default cache priority.
/// </remarks>
/// <param name="key">
--- 140,146 ----
/// </summary>
/// <remarks>
! /// If <paramref name="timeToLive"/> equals <see cref="TimeSpan.MinValue"/>,
! /// or <see cref="EnforceTimeToLive"/> is <value>true</value>, this cache
! /// instance's <see cref="TimeToLive"/> value will be applied.
/// </remarks>
/// <param name="key">
***************
*** 117,134 ****
/// </param>
/// <param name="timeToLive">
! /// Item's time-to-live (TTL) in milliseconds.
! /// </param>
! /// <param name="slidingExpiration">
! /// Flag specifying whether the item's time-to-live should be reset
! /// when the item is accessed.
/// </param>
! public virtual void Insert(object key, object value, int timeToLive, bool slidingExpiration)
{
! Insert(key, value, timeToLive, slidingExpiration, CachePriority.Default);
}
/// <summary>
! /// Inserts an item into the cache.
/// </summary>
/// <param name="key">
/// Item key.
--- 151,171 ----
/// </param>
/// <param name="timeToLive">
! /// Item's time-to-live (TTL).
/// </param>
! public virtual void Insert(object key, object value, TimeSpan timeToLive)
{
! if (TimeSpan.MinValue.Equals(timeToLive) || _enforceTimeToLive)
! {
! timeToLive = _timeToLive;
! }
! DoInsert(key, value, timeToLive);
}
/// <summary>
! /// Actually does the cache implementation specific insert operation into the cache.
/// </summary>
+ /// <remarks>
+ /// Items inserted using this method have default cache priority.
+ /// </remarks>
/// <param name="key">
/// Item key.
***************
*** 138,153 ****
/// </param>
/// <param name="timeToLive">
! /// Item's time-to-live (TTL) in milliseconds.
! /// </param>
! /// <param name="slidingExpiration">
! /// Flag specifying whether the item's time-to-live should be reset
! /// when the item is accessed.
! /// </param>
! /// <param name="priority">
! /// Item priority.
/// </param>
! public abstract void Insert(object key, object value, int timeToLive, bool slidingExpiration,
! CachePriority priority);
!
}
}
\ No newline at end of file
--- 175,181 ----
/// </param>
/// <param name="timeToLive">
! /// Item's time-to-live (TTL).
/// </param>
! protected abstract void DoInsert(object key, object value, TimeSpan timeToLive);
}
}
\ No newline at end of file
--- CachePriority.cs DELETED ---
Index: NonExpiringCache.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Caching/NonExpiringCache.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** NonExpiringCache.cs 16 Feb 2007 01:59:31 -0000 1.3
--- NonExpiringCache.cs 24 Aug 2007 22:43:55 -0000 1.4
***************
*** 19,22 ****
--- 19,23 ----
#endregion
+ using System;
using System.Collections;
***************
*** 31,35 ****
public class NonExpiringCache : AbstractCache
{
! private IDictionary itemStore = new Hashtable();
/// <summary>
--- 32,36 ----
public class NonExpiringCache : AbstractCache
{
! private readonly IDictionary itemStore = new Hashtable();
/// <summary>
***************
*** 132,144 ****
/// Item's time-to-live (TTL) in milliseconds.
/// </param>
! /// <param name="slidingExpiration">
! /// Flag specifying whether the item's time-to-live should be reset
! /// when the item is accessed.
! /// </param>
! /// <param name="priority">
! /// Item priority.
! /// </param>
! public override void Insert(object key, object value, int timeToLive, bool slidingExpiration,
! CachePriority priority)
{
lock (itemStore.SyncRoot)
--- 133,137 ----
/// Item's time-to-live (TTL) in milliseconds.
/// </param>
! protected override void DoInsert(object key, object value, TimeSpan timeToLive)
{
lock (itemStore.SyncRoot)
Index: ICache.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Caching/ICache.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** ICache.cs 9 Feb 2007 07:12:23 -0000 1.2
--- ICache.cs 24 Aug 2007 22:43:55 -0000 1.3
***************
*** 19,22 ****
--- 19,23 ----
#endregion
+ using System;
using System.Collections;
***************
*** 100,122 ****
/// </param>
/// <param name="timeToLive">
! /// Item's time-to-live (TTL) in milliseconds.
! /// </param>
! /// <param name="slidingExpiration">
! /// Flag specifying whether the item's time-to-live should be reset
! /// when the item is accessed.
! /// </param>
! void Insert(object key, object value, int timeToLive, bool slidingExpiration);
!
! /// <summary>
! /// Inserts an item into the cache.
! /// </summary>
! /// <param name="key">
! /// Item key.
! /// </param>
! /// <param name="value">
! /// Item value.
! /// </param>
! /// <param name="timeToLive">
! /// Item's time-to-live (TTL) in milliseconds.
/// </param>
/// <param name="slidingExpiration">
--- 101,105 ----
/// </param>
/// <param name="timeToLive">
! /// Item's time-to-live.
/// </param>
/// <param name="slidingExpiration">
***************
*** 124,131 ****
/// when the item is accessed.
/// </param>
! /// <param name="priority">
! /// Item priority.
! /// </param>
! void Insert(object key, object value, int timeToLive, bool slidingExpiration, CachePriority priority);
}
}
\ No newline at end of file
--- 107,111 ----
/// when the item is accessed.
/// </param>
! void Insert(object key, object value, TimeSpan timeToLive);
}
}
\ No newline at end of file
Index: BaseCacheAttribute.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Caching/BaseCacheAttribute.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** BaseCacheAttribute.cs 1 Apr 2007 15:04:39 -0000 1.3
--- BaseCacheAttribute.cs 24 Aug 2007 22:43:55 -0000 1.4
***************
*** 19,25 ****
private string condition;
private IExpression conditionExpression;
! private int timeToLive = 0;
! private bool slidingExpiration = false;
! private CachePriority priority = CachePriority.Default;
#endregion
--- 19,24 ----
private string condition;
private IExpression conditionExpression;
! private string timeToLive = null;
! private TimeSpan timeToLiveTimeSpan = TimeSpan.MinValue;
#endregion
***************
*** 129,178 ****
/// <summary>
! /// The amount of time an object should remain in the cache (in seconds).
/// </summary>
/// <remarks>
! /// <p>
! /// The default time is 0, which means that an object will never expire.
! /// </p>
/// </remarks>
/// <value>
! /// The amount of time object should remain in the cache (in seconds).
/// </value>
! public int TimeToLive
{
get { return timeToLive; }
! set { timeToLive = value; }
}
/// <summary>
! /// Is a sliding expiration cache strategy to be used?
/// </summary>
/// <remarks>
! /// <p>
! /// If this property value is set to <see lang="true"/>, every time the
! /// marked object is accessed it's
! /// <see cref="TimeToLive"/> property
! /// value must be reset to it's original value.
! /// </p>
/// </remarks>
/// <value>
! /// <see lang="true"/> if sliding expiration is to be used.
! /// </value>
! public bool SlidingExpiration
! {
! get { return slidingExpiration; }
! set { slidingExpiration = value; }
! }
!
! /// <summary>
! /// The cache priority for the item.
! /// </summary>
! /// <value>
! /// One of the <see cref="CachePriority"/> enumeration values.
/// </value>
! public CachePriority Priority
{
! get { return priority; }
! set { priority = value; }
}
--- 128,165 ----
/// <summary>
! /// The amount of time an object should remain in the cache.
/// </summary>
/// <remarks>
! /// If no TTL is specified, the default TTL defined by the
! /// cache's policy will be applied.
/// </remarks>
/// <value>
! /// The amount of time object should remain in the cache
! /// formatted to be recognizable by <see cref="TimeSpan.Parse(string)"/>.
/// </value>
! public string TimeToLive
{
get { return timeToLive; }
! set
! {
! timeToLive = value;
! timeToLiveTimeSpan = (timeToLive == null) ? TimeSpan.MinValue : TimeSpan.Parse(timeToLive);
! }
}
+
/// <summary>
! /// The amount of time an object should remain in the cache (in seconds).
/// </summary>
/// <remarks>
! /// If no TTL is specified, the default TTL defined by the
! /// cache's policy will be applied.
/// </remarks>
/// <value>
! /// The amount of time object should remain in the cache (in seconds).
/// </value>
! public TimeSpan TimeToLiveTimeSpan
{
! get { return timeToLiveTimeSpan; }
}
|