From: Kevin W. <kev...@us...> - 2005-02-17 15:08:45
|
Update of /cvsroot/nhibernate/NHibernateContrib/src/NHibernate.Caches.Prevalence In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1382 Modified Files: PrevalenceCache.cs PrevalenceCacheFixture.cs Log Message: implement region handling thanks to James McKay for the code suggestion Index: PrevalenceCacheFixture.cs =================================================================== RCS file: /cvsroot/nhibernate/NHibernateContrib/src/NHibernate.Caches.Prevalence/PrevalenceCacheFixture.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PrevalenceCacheFixture.cs 13 Jan 2005 23:10:33 -0000 1.1 --- PrevalenceCacheFixture.cs 17 Feb 2005 15:08:36 -0000 1.2 *************** *** 138,141 **** --- 138,156 ---- cache.Remove( null ); } + + [Test] + public void TestRegions() + { + string key = "key"; + ICache cache1 = provider.BuildCache( "nunit1", props ); + ICache cache2 = provider.BuildCache( "nunit2", props ); + string s1 = "test1"; + string s2 = "test2"; + cache1.Put( key, s1 ); + cache2.Put( key, s2 ); + object get1 = cache1.Get( key ); + object get2 = cache2.Get( key ); + Assert.IsFalse( get1 == get2 ); + } } } \ No newline at end of file Index: PrevalenceCache.cs =================================================================== RCS file: /cvsroot/nhibernate/NHibernateContrib/src/NHibernate.Caches.Prevalence/PrevalenceCache.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PrevalenceCache.cs 13 Jan 2005 23:10:32 -0000 1.1 --- PrevalenceCache.cs 17 Feb 2005 15:08:36 -0000 1.2 *************** *** 14,17 **** --- 14,18 ---- { private static readonly ILog log = LogManager.GetLogger( typeof( PrevalenceCache ) ); + private static readonly string _cacheKeyPrefix = "NHibernate-Cache:"; private string _region; private PrevalenceEngine _engine; *************** *** 21,25 **** /// default constructor /// </summary> ! public PrevalenceCache() : this( null, null ) { } --- 22,26 ---- /// default constructor /// </summary> ! public PrevalenceCache() : this( "nhibernate", null ) { } *************** *** 50,54 **** private void Configure( IDictionary properties ) { ! string dataDir = Path.Combine( Environment.CurrentDirectory, "data" ); if( properties != null ) --- 51,55 ---- private void Configure( IDictionary properties ) { ! string dataDir = Path.Combine( Environment.CurrentDirectory, _region ); if( properties != null ) *************** *** 83,86 **** --- 84,92 ---- } + private string GetCacheKey( object key ) + { + return String.Concat( _cacheKeyPrefix, _region, ":", key.ToString() ); + } + /// <summary></summary> /// <param name="key"></param> *************** *** 92,100 **** return null; } if( log.IsDebugEnabled ) { ! log.Debug( "getting object with key: " + key.ToString() ); } ! return _system.Get( key ); } --- 98,107 ---- return null; } + string cacheKey = GetCacheKey( key ); if( log.IsDebugEnabled ) { ! log.Debug( String.Format( "Fetching object '{0}' from the cache.", cacheKey ) ); } ! return _system.Get( cacheKey ); } *************** *** 120,128 **** throw new ArgumentNullException( "value", "null value not allowed" ); } if( log.IsDebugEnabled ) { ! log.Debug( String.Format( "setting value {1} for key {0}", key.ToString(), value.ToString() ) ); } ! _system.Add( key, value ); } --- 127,136 ---- throw new ArgumentNullException( "value", "null value not allowed" ); } + string cacheKey = GetCacheKey( key ); if( log.IsDebugEnabled ) { ! log.Debug( String.Format( "setting value {1} for key {0}", cacheKey, value.ToString() ) ); } ! _system.Add( cacheKey, value ); } *************** *** 139,147 **** throw new ArgumentNullException( "key" ); } if( log.IsDebugEnabled ) { ! log.Debug( "removing item with key: " + key.ToString() ); } ! _system.Remove( key ); } --- 147,156 ---- throw new ArgumentNullException( "key" ); } + string cacheKey = GetCacheKey( key ); if( log.IsDebugEnabled ) { ! log.Debug( "removing item with key: " + cacheKey ); } ! _system.Remove( cacheKey ); } *************** *** 171,174 **** --- 180,184 ---- set { _region = value; } } + #region IDisposable Members |