From: Kevin W. <kev...@us...> - 2004-12-31 15:24:45
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Cache In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18449 Modified Files: CachedItem.cs CacheException.cs CacheFactory.cs HashtableCache.cs HashtableCacheProvider.cs ICache.cs ICacheConcurrencyStrategy.cs ICacheProvider.cs NonstrictReadWriteCache.cs ReadOnlyCache.cs ReadWriteCache.cs Timestamper.cs Log Message: fixing xml comments and letting ReSharper do reformatting Index: CacheFactory.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Cache/CacheFactory.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CacheFactory.cs 20 Dec 2004 04:48:29 -0000 1.3 --- CacheFactory.cs 31 Dec 2004 15:24:29 -0000 1.4 *************** *** 1,4 **** - using System; using System.Xml; namespace NHibernate.Cache --- 1,4 ---- using System.Xml; + using log4net; namespace NHibernate.Cache *************** *** 9,13 **** public class CacheFactory { ! private static readonly log4net.ILog log = log4net.LogManager.GetLogger( typeof(CacheFactory) ); private CacheFactory() --- 9,13 ---- public class CacheFactory { ! private static readonly ILog log = LogManager.GetLogger( typeof( CacheFactory ) ); private CacheFactory() *************** *** 16,21 **** --- 16,24 ---- } + /// <summary></summary> public const string ReadOnly = "read-only"; + /// <summary></summary> public const string ReadWrite = "read-write"; + /// <summary></summary> public const string NonstrictReadWrite = "nonstrict-read-write"; *************** *** 27,35 **** /// <param name="mutable"><c>true</c> if the object being stored in the cache is mutable.</param> /// <returns>An <see cref="ICacheConcurrencyStrategy"/> to use for this object in the <see cref="ICache"/>.</returns> ! public static ICacheConcurrencyStrategy CreateCache(XmlNode node, string name, bool mutable) { ! return CacheFactory.CreateCache( node.Attributes["usage"].Value, name, mutable ); } ! /// <summary> /// Creates an <see cref="ICacheConcurrencyStrategy"/> from the parameters. --- 30,38 ---- /// <param name="mutable"><c>true</c> if the object being stored in the cache is mutable.</param> /// <returns>An <see cref="ICacheConcurrencyStrategy"/> to use for this object in the <see cref="ICache"/>.</returns> ! public static ICacheConcurrencyStrategy CreateCache( XmlNode node, string name, bool mutable ) { ! return CacheFactory.CreateCache( node.Attributes[ "usage" ].Value, name, mutable ); } ! /// <summary> /// Creates an <see cref="ICacheConcurrencyStrategy"/> from the parameters. *************** *** 40,55 **** /// <returns>An <see cref="ICacheConcurrencyStrategy"/> to use for this object in the <see cref="ICache"/>.</returns> // was private in h2.1 ! public static ICacheConcurrencyStrategy CreateCache(string usage, string name, bool mutable) { ! if( log.IsDebugEnabled ) { log.Debug( "cache for: " + name + "usage strategy: " + usage ); } ! ICacheConcurrencyStrategy ccs = null; ! switch( usage ) { ! case CacheFactory.ReadOnly : ! if( mutable ) { log.Warn( "read-only cache configured for mutable: " + name ); --- 43,58 ---- /// <returns>An <see cref="ICacheConcurrencyStrategy"/> to use for this object in the <see cref="ICache"/>.</returns> // was private in h2.1 ! public static ICacheConcurrencyStrategy CreateCache( string usage, string name, bool mutable ) { ! if( log.IsDebugEnabled ) { log.Debug( "cache for: " + name + "usage strategy: " + usage ); } ! ICacheConcurrencyStrategy ccs = null; ! switch( usage ) { ! case CacheFactory.ReadOnly: ! if( mutable ) { log.Warn( "read-only cache configured for mutable: " + name ); *************** *** 57,74 **** ccs = new ReadOnlyCache(); break; ! case CacheFactory.ReadWrite : ccs = new ReadWriteCache(); break; ! case CacheFactory.NonstrictReadWrite : ccs = new NonstrictReadWriteCache(); break; ! default : throw new MappingException( "cache usage attribute should be read-write, read-only, nonstrict-read-write, or transactional" ); } return ccs; ! } } ! } --- 60,77 ---- ccs = new ReadOnlyCache(); break; ! case CacheFactory.ReadWrite: ccs = new ReadWriteCache(); break; ! case CacheFactory.NonstrictReadWrite: ccs = new NonstrictReadWriteCache(); break; ! default: throw new MappingException( "cache usage attribute should be read-write, read-only, nonstrict-read-write, or transactional" ); } return ccs; ! } } ! } \ No newline at end of file Index: CachedItem.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Cache/CachedItem.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** CachedItem.cs 20 Dec 2004 04:48:28 -0000 1.4 --- CachedItem.cs 31 Dec 2004 15:24:29 -0000 1.5 *************** *** 16,19 **** --- 16,23 ---- private object value; + /// <summary> + /// + /// </summary> + /// <param name="value"></param> public CachedItem(object value) { *************** *** 32,35 **** --- 36,42 ---- } + /// <summary> + /// + /// </summary> public long UnlockTimestamp { Index: Timestamper.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Cache/Timestamper.cs,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Timestamper.cs 20 Dec 2004 04:48:29 -0000 1.8 --- Timestamper.cs 31 Dec 2004 15:24:29 -0000 1.9 *************** *** 1,5 **** using System; ! namespace NHibernate.Cache { /// <summary> --- 1,5 ---- using System; ! namespace NHibernate.Cache { /// <summary> *************** *** 10,39 **** /// strickly increasing, but usually are. /// </remarks> ! public sealed class Timestamper { private static object lockObject = new object(); ! // hibernate is using System.currentMilliSeconds which is calculated // from jan 1, 1970 ! private static long baseDateMs = (new DateTime(1970, 1, 1).Ticks)/10000; ! private static short counter = 0; private static long time; private const int BinDigits = 12; ! public const short OneMs = 1<<BinDigits; //(4096 is the value) ! public static long Next() { ! lock( lockObject ) { // Ticks is accurate down to 100 nanoseconds - hibernate uses milliseconds // to help calculate next time so drop the nanoseconds portion.(1ms==1000000ns) ! long newTime = ( (System.DateTime.Now.Ticks/10000) - baseDateMs ) << BinDigits; ! if (time < newTime) { time = newTime; counter = 0; ! } ! else if (counter < OneMs - 1) { counter++; --- 10,44 ---- /// strickly increasing, but usually are. /// </remarks> ! public sealed class Timestamper { private static object lockObject = new object(); ! // hibernate is using System.currentMilliSeconds which is calculated // from jan 1, 1970 ! private static long baseDateMs = ( new DateTime( 1970, 1, 1 ).Ticks )/10000; ! private static short counter = 0; private static long time; private const int BinDigits = 12; ! /// <summary></summary> ! public const short OneMs = 1 << BinDigits; //(4096 is the value) ! /// <summary> ! /// ! /// </summary> ! /// <returns></returns> ! public static long Next() { ! lock( lockObject ) { // Ticks is accurate down to 100 nanoseconds - hibernate uses milliseconds // to help calculate next time so drop the nanoseconds portion.(1ms==1000000ns) ! long newTime = ( ( DateTime.Now.Ticks/10000 ) - baseDateMs ) << BinDigits; ! if( time < newTime ) { time = newTime; counter = 0; ! } ! else if( counter < OneMs - 1 ) { counter++; *************** *** 48,50 **** } } ! } --- 53,55 ---- } } ! } \ No newline at end of file Index: ICacheProvider.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Cache/ICacheProvider.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ICacheProvider.cs 30 Oct 2004 21:20:17 -0000 1.2 --- ICacheProvider.cs 31 Dec 2004 15:24:29 -0000 1.3 *************** *** 1,11 **** - using System; using System.Collections; ! namespace NHibernate.Cache { /// <summary> /// Support for pluggable caches /// </summary> ! public interface ICacheProvider { /// <summary> --- 1,10 ---- using System.Collections; ! namespace NHibernate.Cache { /// <summary> /// Support for pluggable caches /// </summary> ! public interface ICacheProvider { /// <summary> *************** *** 15,20 **** /// <param name="properties">configuration settings</param> /// <returns></returns> ! ICache BuildCache(string regionName, IDictionary properties ); ! /// <summary> /// generate a timestamp --- 14,19 ---- /// <param name="properties">configuration settings</param> /// <returns></returns> ! ICache BuildCache( string regionName, IDictionary properties ); ! /// <summary> /// generate a timestamp *************** *** 23,26 **** long NextTimestamp(); } ! } ! --- 22,24 ---- long NextTimestamp(); } ! } \ No newline at end of file Index: NonstrictReadWriteCache.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Cache/NonstrictReadWriteCache.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** NonstrictReadWriteCache.cs 29 Oct 2004 05:55:26 -0000 1.3 --- NonstrictReadWriteCache.cs 31 Dec 2004 15:24:29 -0000 1.4 *************** *** 1,5 **** using System; ! namespace NHibernate.Cache { /// <summary> --- 1,6 ---- using System; + using log4net; ! namespace NHibernate.Cache { /// <summary> *************** *** 8,17 **** public class NonstrictReadWriteCache : ICacheConcurrencyStrategy { ! private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(NonstrictReadWriteCache)); private static readonly long timeout = 10000; private ICache _cache; ! public NonstrictReadWriteCache() { } --- 9,19 ---- public class NonstrictReadWriteCache : ICacheConcurrencyStrategy { ! private static readonly ILog log = LogManager.GetLogger( typeof( NonstrictReadWriteCache ) ); private static readonly long timeout = 10000; private ICache _cache; ! /// <summary></summary> ! public NonstrictReadWriteCache() { } *************** *** 19,33 **** #region ICacheConcurrencyStrategy Members ! public object Get(object key, long txTimestamp) { ! if( log.IsDebugEnabled ) { log.Debug( "Cache lookup: " + key ); } ! object result = _cache.Get(key); ! if( result!=null & !(result is Int64) ) { ! if (log.IsDebugEnabled) { log.Debug( "Cache hit" ); --- 21,41 ---- #region ICacheConcurrencyStrategy Members ! /// <summary> ! /// ! /// </summary> ! /// <param name="key"></param> ! /// <param name="txTimestamp"></param> ! /// <returns></returns> ! public object Get( object key, long txTimestamp ) { ! if( log.IsDebugEnabled ) { log.Debug( "Cache lookup: " + key ); } ! object result = _cache.Get( key ); ! if( result != null & !( result is Int64 ) ) { ! if( log.IsDebugEnabled ) { log.Debug( "Cache hit" ); *************** *** 35,41 **** return result; } ! else { ! if( log.IsDebugEnabled ) { log.Debug( "Cache miss" ); --- 43,49 ---- return result; } ! else { ! if( log.IsDebugEnabled ) { log.Debug( "Cache miss" ); *************** *** 46,69 **** } ! public bool Put(object key, object value, long txTimestamp) { object result = _cache.Get( key ); ! if( result==null ) { ! if( log.IsDebugEnabled ) { ! log.Debug("Caching new: " + key); } } ! else if( (result is Int64) && ( (Int64)result < txTimestamp / Timestamper.OneMs ) ) { // note that this is not guaranteed to be correct in a cluster // because system times could be inconsistent ! if( log.IsDebugEnabled ) { log.Debug( "Caching invalidated: " + key ); } } ! else { return false; // note early exit --- 54,84 ---- } ! /// <summary> ! /// ! /// </summary> ! /// <param name="key"></param> ! /// <param name="value"></param> ! /// <param name="txTimestamp"></param> ! /// <returns></returns> ! public bool Put( object key, object value, long txTimestamp ) { object result = _cache.Get( key ); ! if( result == null ) { ! if( log.IsDebugEnabled ) { ! log.Debug( "Caching new: " + key ); } } ! else if( ( result is Int64 ) && ( ( Int64 ) result < txTimestamp/Timestamper.OneMs ) ) { // note that this is not guaranteed to be correct in a cluster // because system times could be inconsistent ! if( log.IsDebugEnabled ) { log.Debug( "Caching invalidated: " + key ); } } ! else { return false; // note early exit *************** *** 74,86 **** } ! public void Lock(object key) { // in case the server crashes, we need the lock to timeout ! _cache.Put( key, ( timeout + Timestamper.Next() / Timestamper.OneMs ) ); } ! public void Release(object key) { ! if( log.IsDebugEnabled ) { log.Debug( "Invalidating: " + key ); --- 89,109 ---- } ! /// <summary> ! /// ! /// </summary> ! /// <param name="key"></param> ! public void Lock( object key ) { // in case the server crashes, we need the lock to timeout ! _cache.Put( key, ( timeout + Timestamper.Next()/Timestamper.OneMs ) ); } ! /// <summary> ! /// ! /// </summary> ! /// <param name="key"></param> ! public void Release( object key ) { ! if( log.IsDebugEnabled ) { log.Debug( "Invalidating: " + key ); *************** *** 88,97 **** //remove the lock (any later transactions can recache) ! _cache.Put( key, Timestamper.Next() / Timestamper.OneMs ); } ! public void Remove(object key) { ! if( log.IsDebugEnabled ) { log.Debug( "Removing: " + key ); --- 111,124 ---- //remove the lock (any later transactions can recache) ! _cache.Put( key, Timestamper.Next()/Timestamper.OneMs ); } ! /// <summary> ! /// ! /// </summary> ! /// <param name="key"></param> ! public void Remove( object key ) { ! if( log.IsDebugEnabled ) { log.Debug( "Removing: " + key ); *************** *** 100,106 **** } public void Clear() { ! if( log.IsDebugEnabled ) { log.Debug( "Clearing" ); --- 127,134 ---- } + /// <summary></summary> public void Clear() { ! if( log.IsDebugEnabled ) { log.Debug( "Clearing" ); *************** *** 109,119 **** } public void Destroy() { ! try { _cache.Destroy(); } ! catch(Exception e) { log.Warn( "Could not destroy cache", e ); --- 137,148 ---- } + /// <summary></summary> public void Destroy() { ! try { _cache.Destroy(); } ! catch( Exception e ) { log.Warn( "Could not destroy cache", e ); *************** *** 121,125 **** } ! public ICache Cache { get { return _cache; } --- 150,155 ---- } ! /// <summary></summary> ! public ICache Cache { get { return _cache; } *************** *** 129,131 **** #endregion } ! } --- 159,161 ---- #endregion } ! } \ No newline at end of file Index: HashtableCacheProvider.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Cache/HashtableCacheProvider.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** HashtableCacheProvider.cs 30 Oct 2004 21:20:17 -0000 1.2 --- HashtableCacheProvider.cs 31 Dec 2004 15:24:29 -0000 1.3 *************** *** 1,6 **** - using System; using System.Collections; ! namespace NHibernate.Cache { /// <summary> --- 1,5 ---- using System.Collections; ! namespace NHibernate.Cache { /// <summary> *************** *** 12,20 **** #region ICacheProvider Members ! public ICache BuildCache(string regionName, IDictionary properties) { return new HashtableCache( regionName ); } public long NextTimestamp() { --- 11,29 ---- #region ICacheProvider Members ! /// <summary> ! /// ! /// </summary> ! /// <param name="regionName"></param> ! /// <param name="properties"></param> ! /// <returns></returns> ! public ICache BuildCache( string regionName, IDictionary properties ) { return new HashtableCache( regionName ); } + /// <summary> + /// + /// </summary> + /// <returns></returns> public long NextTimestamp() { *************** *** 24,26 **** #endregion } ! } --- 33,35 ---- #endregion } ! } \ No newline at end of file Index: ICacheConcurrencyStrategy.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Cache/ICacheConcurrencyStrategy.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ICacheConcurrencyStrategy.cs 20 Dec 2004 04:48:29 -0000 1.4 --- ICacheConcurrencyStrategy.cs 31 Dec 2004 15:24:29 -0000 1.5 *************** *** 1,5 **** ! using System; ! ! namespace NHibernate.Cache { /// <summary> --- 1,3 ---- ! namespace NHibernate.Cache { /// <summary> *************** *** 16,21 **** /// </para> /// </remarks> ! public interface ICacheConcurrencyStrategy ! { /// <summary> /// Attempt to retrieve an object from the Cache --- 14,19 ---- /// </para> /// </remarks> ! public interface ICacheConcurrencyStrategy ! { /// <summary> /// Attempt to retrieve an object from the Cache *************** *** 25,29 **** /// <returns>The cached object or <c>null</c></returns> /// <exception cref="CacheException"></exception> ! object Get(object key, long txTimestamp); /// <summary> --- 23,27 ---- /// <returns>The cached object or <c>null</c></returns> /// <exception cref="CacheException"></exception> ! object Get( object key, long txTimestamp ); /// <summary> *************** *** 35,39 **** /// <returns><c>true</c> if the object was successfully cached</returns> /// <exception cref="CacheException"></exception> ! bool Put(object key, object value, long txTimestamp); /// <summary> --- 33,37 ---- /// <returns><c>true</c> if the object was successfully cached</returns> /// <exception cref="CacheException"></exception> ! bool Put( object key, object value, long txTimestamp ); /// <summary> *************** *** 42,46 **** /// <param name="key">The key</param> /// <exception cref="CacheException"></exception> ! void Lock(object key); /// <summary> --- 40,44 ---- /// <param name="key">The key</param> /// <exception cref="CacheException"></exception> ! void Lock( object key ); /// <summary> *************** *** 49,53 **** /// <param name="key">The key</param> /// <exception cref="CacheException"></exception> ! void Release(object key); /// <summary> --- 47,51 ---- /// <param name="key">The key</param> /// <exception cref="CacheException"></exception> ! void Release( object key ); /// <summary> *************** *** 56,60 **** /// <param name="key"></param> /// <exception cref="CacheException"></exception> ! void Remove(object key); /// <summary> --- 54,58 ---- /// <param name="key"></param> /// <exception cref="CacheException"></exception> ! void Remove( object key ); /// <summary> *************** *** 74,78 **** /// </summary> /// <value>The <see cref="ICache"/> for this strategy to use.</value> ! ICache Cache { get; set ;} } ! } --- 72,76 ---- /// </summary> /// <value>The <see cref="ICache"/> for this strategy to use.</value> ! ICache Cache { get; set; } } ! } \ No newline at end of file Index: ReadWriteCache.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Cache/ReadWriteCache.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ReadWriteCache.cs 20 Dec 2004 04:48:29 -0000 1.6 --- ReadWriteCache.cs 31 Dec 2004 15:24:29 -0000 1.7 *************** *** 1,5 **** using System; ! namespace NHibernate.Cache { /// <summary> --- 1,6 ---- using System; + using log4net; ! namespace NHibernate.Cache { /// <summary> *************** *** 10,20 **** /// Works at the "Read Committed" isolation level /// </remarks> ! public class ReadWriteCache : ICacheConcurrencyStrategy { ! private static readonly log4net.ILog log = log4net.LogManager.GetLogger( typeof(ReadWriteCache) ); private readonly object lockObject = new object(); private ICache _cache; ! public ReadWriteCache() { } --- 11,22 ---- /// Works at the "Read Committed" isolation level /// </remarks> ! public class ReadWriteCache : ICacheConcurrencyStrategy { ! private static readonly ILog log = LogManager.GetLogger( typeof( ReadWriteCache ) ); private readonly object lockObject = new object(); private ICache _cache; ! /// <summary></summary> ! public ReadWriteCache() { } *************** *** 22,50 **** #region ICacheConcurrencyStrategy Members ! public object Get(object key, long txTimestamp) { ! lock( lockObject ) { ! if( log.IsDebugEnabled ) { ! log.Debug("Cache lookup: " + key); } ! CachedItem item = _cache.Get(key) as CachedItem; ! if ( ! item!=null && ! item.FreshTimestamp < txTimestamp && ! item.IsFresh // || txTimestamp < item.LockTimestamp ! ) { ! if( log.IsDebugEnabled ) { log.Debug( "Cache hit: " + key ); } return item.Value; ! } ! else { ! if( log.IsDebugEnabled ) { log.Debug( "Cache miss: " + key ); --- 24,58 ---- #region ICacheConcurrencyStrategy Members ! /// <summary> ! /// ! /// </summary> ! /// <param name="key"></param> ! /// <param name="txTimestamp"></param> ! /// <returns></returns> ! public object Get( object key, long txTimestamp ) { ! lock( lockObject ) { ! if( log.IsDebugEnabled ) { ! log.Debug( "Cache lookup: " + key ); } ! CachedItem item = _cache.Get( key ) as CachedItem; ! if( ! item != null && ! item.FreshTimestamp < txTimestamp && ! item.IsFresh // || txTimestamp < item.LockTimestamp ! ) { ! if( log.IsDebugEnabled ) { log.Debug( "Cache hit: " + key ); } return item.Value; ! } ! else { ! if( log.IsDebugEnabled ) { log.Debug( "Cache miss: " + key ); *************** *** 58,72 **** // in this class until unlocked ! public void Lock(object key) { ! lock( lockObject ) { ! if( log.IsDebugEnabled ) { ! log.Debug("Invalidating: " + key); } ! CachedItem item = _cache.Get( key ) as CachedItem; ! if ( item==null ) item = new CachedItem( null ); item.Lock(); _cache.Put( key, item ); --- 66,87 ---- // in this class until unlocked ! /// <summary> ! /// ! /// </summary> ! /// <param name="key"></param> ! public void Lock( object key ) { ! lock( lockObject ) { ! if( log.IsDebugEnabled ) { ! log.Debug( "Invalidating: " + key ); } ! CachedItem item = _cache.Get( key ) as CachedItem; ! if( item == null ) ! { ! item = new CachedItem( null ); ! } item.Lock(); _cache.Put( key, item ); *************** *** 74,102 **** } ! public bool Put(object key, object value, long txTimestamp) { ! lock( lockObject ) { ! if( log.IsDebugEnabled ) { log.Debug( "Caching: " + key ); } ! CachedItem item = _cache.Get( key ) as CachedItem; ! if ( ! item==null || ! (item.IsUnlocked && !item.IsFresh && item.UnlockTimestamp < txTimestamp) ! ) { _cache.Put( key, new CachedItem( value ) ); ! if( log.IsDebugEnabled ) { log.Debug( "Cached: " + key ); } return true; ! } else { ! if( log.IsDebugEnabled ) { log.Debug( "Could not cache: " + key ); --- 89,124 ---- } ! /// <summary> ! /// ! /// </summary> ! /// <param name="key"></param> ! /// <param name="value"></param> ! /// <param name="txTimestamp"></param> ! /// <returns></returns> ! public bool Put( object key, object value, long txTimestamp ) { ! lock( lockObject ) { ! if( log.IsDebugEnabled ) { log.Debug( "Caching: " + key ); } ! CachedItem item = _cache.Get( key ) as CachedItem; ! if( ! item == null || ! ( item.IsUnlocked && !item.IsFresh && item.UnlockTimestamp < txTimestamp ) ! ) { _cache.Put( key, new CachedItem( value ) ); ! if( log.IsDebugEnabled ) { log.Debug( "Cached: " + key ); } return true; ! } else { ! if( log.IsDebugEnabled ) { log.Debug( "Could not cache: " + key ); *************** *** 107,125 **** } ! public void Release(object key) { ! lock( lockObject ) { ! if( log.IsDebugEnabled ) { log.Debug( "Releasing: " + key ); } CachedItem item = _cache.Get( key ) as CachedItem; ! if( item!=null ) { item.Unlock(); _cache.Put( key, item ); ! } ! else { log.Warn( "An item was expired by the cache while it was locked" ); --- 129,151 ---- } ! /// <summary> ! /// ! /// </summary> ! /// <param name="key"></param> ! public void Release( object key ) { ! lock( lockObject ) { ! if( log.IsDebugEnabled ) { log.Debug( "Releasing: " + key ); } CachedItem item = _cache.Get( key ) as CachedItem; ! if( item != null ) { item.Unlock(); _cache.Put( key, item ); ! } ! else { log.Warn( "An item was expired by the cache while it was locked" ); *************** *** 128,148 **** } ! public void Clear() { _cache.Clear(); } ! public void Remove(object key) { _cache.Remove( key ); } ! public void Destroy() { ! try { _cache.Destroy(); } ! catch(Exception e) { log.Warn( "Could not destroy cache", e ); --- 154,184 ---- } ! /// <summary> ! /// ! /// </summary> ! public void Clear() { _cache.Clear(); } ! /// <summary> ! /// ! /// </summary> ! /// <param name="key"></param> ! public void Remove( object key ) { _cache.Remove( key ); } ! /// <summary> ! /// ! /// </summary> ! public void Destroy() { ! try { _cache.Destroy(); } ! catch( Exception e ) { log.Warn( "Could not destroy cache", e ); *************** *** 150,154 **** } ! public ICache Cache { get { return _cache; } --- 186,193 ---- } ! /// <summary> ! /// ! /// </summary> ! public ICache Cache { get { return _cache; } *************** *** 157,161 **** #endregion - } ! } --- 196,199 ---- #endregion } ! } \ No newline at end of file Index: HashtableCache.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Cache/HashtableCache.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** HashtableCache.cs 29 Oct 2004 05:55:26 -0000 1.4 --- HashtableCache.cs 31 Dec 2004 15:24:29 -0000 1.5 *************** *** 1,7 **** - using System; using System.Collections; - using System.Runtime.CompilerServices; ! namespace NHibernate.Cache { /// <summary> --- 1,5 ---- using System.Collections; ! namespace NHibernate.Cache { /// <summary> *************** *** 10,18 **** public class HashtableCache : ICache { ! private static object synchObject = new object(); private Hashtable cache = new Hashtable(); private string region; ! public HashtableCache(string region) { this.region = region; --- 8,20 ---- public class HashtableCache : ICache { ! // private static object synchObject = new object(); private Hashtable cache = new Hashtable(); private string region; ! /// <summary> ! /// ! /// </summary> ! /// <param name="region"></param> ! public HashtableCache( string region ) { this.region = region; *************** *** 20,39 **** #region ICache Members ! ! public object Get(object key) { ! return cache[key]; } ! public void Put(object key, object value) { ! cache[key] = value; } ! public void Remove(object key) { ! cache.Remove(key); } public void Clear() { --- 22,45 ---- #region ICache Members ! ! /// <summary></summary> ! public object Get( object key ) { ! return cache[ key ]; } ! /// <summary></summary> ! public void Put( object key, object value ) { ! cache[ key ] = value; } ! /// <summary></summary> ! public void Remove( object key ) { ! cache.Remove( key ); } + /// <summary></summary> public void Clear() { *************** *** 49,58 **** } public string Region { ! set { region = value; } } #endregion } ! } --- 55,65 ---- } + /// <summary></summary> public string Region { ! set { region = value; } } #endregion } ! } \ No newline at end of file Index: ReadOnlyCache.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Cache/ReadOnlyCache.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** ReadOnlyCache.cs 20 Dec 2004 04:48:29 -0000 1.7 --- ReadOnlyCache.cs 31 Dec 2004 15:24:29 -0000 1.8 *************** *** 1,17 **** using System; ! namespace NHibernate.Cache { /// <summary> /// Caches data that is never updated /// </summary> ! public class ReadOnlyCache : ICacheConcurrencyStrategy { ! private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(ReadOnlyCache)); ! private object lockObject = new object(); private ICache _cache; ! public ReadOnlyCache() { } --- 1,19 ---- using System; + using log4net; ! namespace NHibernate.Cache { /// <summary> /// Caches data that is never updated /// </summary> ! public class ReadOnlyCache : ICacheConcurrencyStrategy { ! private static readonly ILog log = LogManager.GetLogger( typeof( ReadOnlyCache ) ); ! private object lockObject = new object(); private ICache _cache; ! /// <summary></summary> ! public ReadOnlyCache() { } *************** *** 19,27 **** #region ICacheConcurrencyStrategy Members ! public object Get(object key, long timestamp) { ! lock( lockObject ) { ! if( log.IsDebugEnabled ) { log.Debug( "Cache lookup: " + key ); --- 21,35 ---- #region ICacheConcurrencyStrategy Members ! /// <summary> ! /// ! /// </summary> ! /// <param name="key"></param> ! /// <param name="timestamp"></param> ! /// <returns></returns> ! public object Get( object key, long timestamp ) { ! lock( lockObject ) { ! if( log.IsDebugEnabled ) { log.Debug( "Cache lookup: " + key ); *************** *** 29,33 **** object result = _cache.Get( key ); ! if ( result!=null && log.IsDebugEnabled ) { log.Debug( "Cache hit" ); --- 37,41 ---- object result = _cache.Get( key ); ! if( result != null && log.IsDebugEnabled ) { log.Debug( "Cache hit" ); *************** *** 41,99 **** } ! public void Lock(object key) { ! log.Error("Application attempted to edit read only item: " + key); ! throw new InvalidOperationException("Can't write to a readonly object"); } ! public bool Put(object key, object value, long timestamp) { ! ! lock( lockObject ) { ! if (log.IsDebugEnabled) { ! log.Debug("Caching: " + key); } ! _cache.Put(key, value); return true; } } ! public void Release(object key) { ! log.Error("Application attempted to edit read only item: " + key); ! throw new InvalidOperationException("Can't write to a readonly object"); } ! public void Clear() { _cache.Clear(); } ! public void Remove(object key) { ! _cache.Remove(key); } ! public void Destroy() { ! try { _cache.Destroy(); } ! catch(Exception e) { ! log.Warn("Could not destroy cache", e); } } ! public ICache Cache { get { return _cache; } set { _cache = value; } } - - #endregion } ! } --- 49,134 ---- } ! /// <summary> ! /// ! /// </summary> ! /// <param name="key"></param> ! public void Lock( object key ) { ! log.Error( "Application attempted to edit read only item: " + key ); ! throw new InvalidOperationException( "Can't write to a readonly object" ); } ! /// <summary> ! /// ! /// </summary> ! /// <param name="key"></param> ! /// <param name="value"></param> ! /// <param name="timestamp"></param> ! /// <returns></returns> ! public bool Put( object key, object value, long timestamp ) ! { ! lock( lockObject ) { ! if( log.IsDebugEnabled ) { ! log.Debug( "Caching: " + key ); } ! _cache.Put( key, value ); return true; } } ! /// <summary> ! /// ! /// </summary> ! /// <param name="key"></param> ! public void Release( object key ) { ! log.Error( "Application attempted to edit read only item: " + key ); ! throw new InvalidOperationException( "Can't write to a readonly object" ); } ! /// <summary> ! /// ! /// </summary> ! public void Clear() { _cache.Clear(); } ! /// <summary> ! /// ! /// </summary> ! /// <param name="key"></param> ! public void Remove( object key ) { ! _cache.Remove( key ); } ! /// <summary> ! /// ! /// </summary> ! public void Destroy() { ! try { _cache.Destroy(); } ! catch( Exception e ) { ! log.Warn( "Could not destroy cache", e ); } } ! /// <summary> ! /// ! /// </summary> ! public ICache Cache { get { return _cache; } set { _cache = value; } } + #endregion } ! } \ No newline at end of file Index: ICache.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Cache/ICache.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ICache.cs 29 Oct 2004 05:55:26 -0000 1.5 --- ICache.cs 31 Dec 2004 15:24:29 -0000 1.6 *************** *** 1,5 **** ! using System; ! ! namespace NHibernate.Cache { /// <summary> --- 1,3 ---- ! namespace NHibernate.Cache { /// <summary> *************** *** 14,20 **** /// </para> /// </remarks> ! public interface ICache { - /// <summary> /// Get the object from the Cache --- 12,17 ---- /// </para> /// </remarks> ! public interface ICache { /// <summary> /// Get the object from the Cache *************** *** 22,28 **** /// <param name="key"></param> /// <returns></returns> ! object Get(object key); ! void Put(object key, object value); /// <summary> --- 19,30 ---- /// <param name="key"></param> /// <returns></returns> ! object Get( object key ); ! /// <summary> ! /// ! /// </summary> ! /// <param name="key"></param> ! /// <param name="value"></param> ! void Put( object key, object value ); /// <summary> *************** *** 31,35 **** /// <param name="key">The Key of the Item in the Cache to remove.</param> /// <exception cref="CacheException"></exception> ! void Remove(object key); /// <summary> --- 33,37 ---- /// <param name="key">The Key of the Item in the Cache to remove.</param> /// <exception cref="CacheException"></exception> ! void Remove( object key ); /// <summary> *************** *** 49,56 **** /// </summary> /// <exception cref="CacheException"></exception> ! string Region {set;} } ! } --- 51,58 ---- /// </summary> /// <exception cref="CacheException"></exception> ! string Region { set; } } ! } \ No newline at end of file Index: CacheException.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Cache/CacheException.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** CacheException.cs 20 Dec 2004 04:48:28 -0000 1.4 --- CacheException.cs 31 Dec 2004 15:24:29 -0000 1.5 *************** *** 9,17 **** public class CacheException : HibernateException { ! public CacheException(string message) : base( message ) { } ! public CacheException(Exception e) : base( e ) { } --- 9,25 ---- public class CacheException : HibernateException { ! /// <summary> ! /// ! /// </summary> ! /// <param name="message"></param> ! public CacheException( string message ) : base( message ) { } ! /// <summary> ! /// ! /// </summary> ! /// <param name="e"></param> ! public CacheException( Exception e ) : base( e ) { } |