From: Kevin W. <kev...@us...> - 2005-02-17 15:04:33
|
Update of /cvsroot/nhibernate/NHibernateContrib/src/BantamTech.SysCache In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv304 Modified Files: AssemblyInfo.cs SysCache.cs SysCacheFixture.cs Log Message: fixing region handling http://jira.nhibernate.org/browse/NH-194 thanks to James McKay Index: SysCacheFixture.cs =================================================================== RCS file: /cvsroot/nhibernate/NHibernateContrib/src/BantamTech.SysCache/SysCacheFixture.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** SysCacheFixture.cs 13 Jan 2005 23:07:23 -0000 1.3 --- SysCacheFixture.cs 17 Feb 2005 15:04:24 -0000 1.4 *************** *** 212,215 **** --- 212,230 ---- 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: SysCache.cs =================================================================== RCS file: /cvsroot/nhibernate/NHibernateContrib/src/BantamTech.SysCache/SysCache.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SysCache.cs 7 Dec 2004 19:59:16 -0000 1.1 --- SysCache.cs 17 Feb 2005 15:04:24 -0000 1.2 *************** *** 45,48 **** --- 45,49 ---- private Hashtable _map; private static readonly TimeSpan _defaultRelativeExpiration = TimeSpan.FromSeconds( 300 ); + private static readonly string _cacheKeyPrefix = "NHibernate-Cache:"; /// <summary> *************** *** 205,208 **** --- 206,214 ---- } + private string GetCacheKey( object key ) + { + return String.Concat( _cacheKeyPrefix, _region, ":", key.ToString() ); + } + /// <summary></summary> /// <param name="key"></param> *************** *** 214,218 **** return null; } ! return _cache.Get( key.ToString() ); } --- 220,229 ---- return null; } ! string cacheKey = GetCacheKey( key ); ! if( log.IsDebugEnabled ) ! { ! log.Debug( String.Format( "Fetching object '{0}' from the cache.", cacheKey ) ); ! } ! return _cache.Get( cacheKey ); } *************** *** 230,240 **** throw new ArgumentNullException( "value", "null value not allowed" ); } ! if( _cache[key.ToString()] != null ) { if( log.IsDebugEnabled ) { ! log.Debug( "updating value of key '" + key.ToString() + "' to: " + value.ToString() ); } ! _cache[key.ToString()] = value; } else --- 241,252 ---- throw new ArgumentNullException( "value", "null value not allowed" ); } ! string cacheKey = GetCacheKey( key ); ! if( _cache[ cacheKey ] != null ) { if( log.IsDebugEnabled ) { ! log.Debug( String.Format("updating value of key '{0}' to '{1}'.", cacheKey, value.ToString() ) ); } ! _cache[ cacheKey ] = value; } else *************** *** 242,252 **** if( log.IsDebugEnabled ) { ! log.Debug( "adding new data: key=" + key.ToString() + "&value=" + value.ToString() ); } ! _map.Add( key.ToString(), value ); ! _cache.Add( key.ToString(), value, null, _absExpiration, _slidingExpiration, _priority, null ); } } /// <summary></summary> /// <param name="key"></param> --- 254,279 ---- if( log.IsDebugEnabled ) { ! log.Debug( String.Format("adding new data: key={0}&value={1}", cacheKey, value.ToString() ) ); } ! _map.Add( cacheKey, value ); ! _cache.Add( ! cacheKey, value, null, ! _absExpiration, _slidingExpiration, _priority, ! new CacheItemRemovedCallback( this.CacheItemRemoved ) ! ); } } + /// <summary> + /// make sure the Hashtable is in sync with the cache by using the callback. + /// </summary> + /// <param name="key"></param> + /// <param name="value"></param> + /// <param name="reason"></param> + public void CacheItemRemoved( string key, object value, CacheItemRemovedReason reason ) + { + _map.Remove( key ); + } + /// <summary></summary> /// <param name="key"></param> *************** *** 257,262 **** throw new ArgumentNullException( "key" ); } ! _map.Remove( key.ToString() ); ! _cache.Remove( key.ToString() ); } --- 284,294 ---- throw new ArgumentNullException( "key" ); } ! string cacheKey = GetCacheKey( key ); ! if( log.IsDebugEnabled ) ! { ! log.Debug( "removing item with key: " + cacheKey ); ! } ! _map.Remove( cacheKey ); // possibly not needed now that callbacks are used ! _cache.Remove( cacheKey ); } *************** *** 264,270 **** public void Clear() { ! foreach( DictionaryEntry entry in _map ) { ! _cache.Remove( entry.Key.ToString() ); } _map.Clear(); --- 296,303 ---- public void Clear() { ! ArrayList keys = new ArrayList( _map.Keys ); ! foreach( object key in keys ) { ! _cache.Remove( key.ToString() ); } _map.Clear(); Index: AssemblyInfo.cs =================================================================== RCS file: /cvsroot/nhibernate/NHibernateContrib/src/BantamTech.SysCache/AssemblyInfo.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** AssemblyInfo.cs 6 Jan 2005 00:23:35 -0000 1.4 --- AssemblyInfo.cs 17 Feb 2005 15:04:24 -0000 1.5 *************** *** 8,12 **** // <autogenerated> // This code was generated by a tool. ! // Runtime Version: 1.1.4322.573 // // Changes to this file may cause incorrect behavior and will be lost if --- 8,12 ---- // <autogenerated> // This code was generated by a tool. ! // Runtime Version: 1.1.4322.2032 // // Changes to this file may cause incorrect behavior and will be lost if *************** *** 22,25 **** [assembly: AssemblyVersionAttribute("0.6.0.0")] [assembly: AssemblyInformationalVersionAttribute("0.6")] - //[assembly: AssemblyKeyFileAttribute("..\\NHibernate.snk")] --- 22,24 ---- |