Author: gbayon
Date: Sun Dec  4 06:53:40 2005
New Revision: 353855

URL: http://svn.apache.org/viewcvs?rev=353855&view=rev
Log:
- Added method Remove on ICacheCoontroller
- Added Nunit tets for CacheCoontroller

Added:
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheController/
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheController/FifoCacheControllerTest.cs
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheController/LruCacheControllerTest.cs
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheController/MemoryCacheControllerTest.cs
Modified:
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.csproj
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/Odbc/ResultClass.xml
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/OleDb/ResultClass.xml
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/ResultClass.xml
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/bin/Debug/SqlMap_PostgreSQL_Npgsql.config
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Cache/Fifo/FifoCacheController.cs
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Cache/ICacheController.cs
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Cache/Lru/LruCacheController.cs
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Cache/Memory/MemoryCacheControler.cs

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.csproj
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.csproj?rev=353855&r1=353854&r2=353855&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.csproj
 (original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.csproj
 Sun Dec  4 06:53:40 2005
@@ -767,6 +767,21 @@
                     BuildAction = "Compile"
                 />
                 <File
+                    RelPath = 
"NUnit\SqlMapTests\CacheController\FifoCacheControllerTest.cs"
+                    SubType = "Code"
+                    BuildAction = "Compile"
+                />
+                <File
+                    RelPath = 
"NUnit\SqlMapTests\CacheController\LruCacheControllerTest.cs"
+                    SubType = "Code"
+                    BuildAction = "Compile"
+                />
+                <File
+                    RelPath = 
"NUnit\SqlMapTests\CacheController\MemoryCacheControllerTest.cs"
+                    SubType = "Code"
+                    BuildAction = "Compile"
+                />
+                <File
                     RelPath = "NUnit\SqlMapTests\MSSQL\EmbedParameterTest.cs"
                     SubType = "Code"
                     BuildAction = "Compile"

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/Odbc/ResultClass.xml
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/Odbc/ResultClass.xml?rev=353855&r1=353854&r2=353855&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/Odbc/ResultClass.xml
 (original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/Odbc/ResultClass.xml
 Sun Dec  4 06:53:40 2005
@@ -29,8 +29,9 @@
                                        resultClass="char" >
                        select cast('a' as char) from Orders where Order_ID = 
#value#
                </statement>
+               <!-- SQL Server provider doesn't know char type, the 
resultClass type must be specified -->
                <statement id="GetCharWithoutResultClass"
-                                       parameterClass="Int"
+                                       parameterClass="Int" resultClass="char" 
                                        extends="GetChar">
                </statement>
                

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/OleDb/ResultClass.xml
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/OleDb/ResultClass.xml?rev=353855&r1=353854&r2=353855&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/OleDb/ResultClass.xml
 (original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/OleDb/ResultClass.xml
 Sun Dec  4 06:53:40 2005
@@ -30,8 +30,9 @@
                                        resultClass="char" >
                        select cast('a' as char) from Orders where Order_ID = 
#value#
                </statement>
+               <!-- SQL Server provider doesn't know char type, the 
resultClass type must be specified -->
                <statement id="GetCharWithoutResultClass"
-                                       parameterClass="Int"
+                                       parameterClass="Int" resultClass="char"
                                        extends="GetChar">
                </statement>
                

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/ResultClass.xml
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/ResultClass.xml?rev=353855&r1=353854&r2=353855&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/ResultClass.xml
 (original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/ResultClass.xml
 Sun Dec  4 06:53:40 2005
@@ -30,8 +30,9 @@
                                        resultClass="char" >
                        select cast('a' as char) from Orders where Order_ID = 
#value#
                </statement>
+               <!-- SQL Server provider doesn't know char type, the 
resultClass type must be specified -->
                <statement id="GetCharWithoutResultClass"
-                                       parameterClass="Int"
+                                       parameterClass="Int" resultClass="char"
                                        extends="GetChar">
                </statement>
                

Added: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheController/FifoCacheControllerTest.cs
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheController/FifoCacheControllerTest.cs?rev=353855&view=auto
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheController/FifoCacheControllerTest.cs
 (added)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheController/FifoCacheControllerTest.cs
 Sun Dec  4 06:53:40 2005
@@ -0,0 +1,19 @@
+using IBatisNet.DataMapper.Configuration.Cache;
+using IBatisNet.DataMapper.Configuration.Cache.Fifo;
+using NUnit.Framework;
+
+namespace IBatisNet.DataMapper.Test.NUnit.SqlMapTests.CacheController
+{
+       /// <summary>
+       /// Description résumée de FifoCacheControllerTest.
+       /// </summary>
+       [TestFixture]
+       public class FifoCacheControllerTest : LruCacheControllerTest
+       {
+
+               protected override ICacheController GetController() 
+               {
+                       return new FifoCacheController();
+               }
+       }
+}

Added: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheController/LruCacheControllerTest.cs
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheController/LruCacheControllerTest.cs?rev=353855&view=auto
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheController/LruCacheControllerTest.cs
 (added)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheController/LruCacheControllerTest.cs
 Sun Dec  4 06:53:40 2005
@@ -0,0 +1,89 @@
+using System.Collections;
+using System.Collections.Specialized;
+using IBatisNet.DataMapper.Configuration.Cache;
+using IBatisNet.DataMapper.Configuration.Cache.Lru;
+using NUnit.Framework;
+
+namespace IBatisNet.DataMapper.Test.NUnit.SqlMapTests.CacheController
+{
+       /// <summary>
+       /// Description résumée de LruCacheControllerTest.
+       /// </summary>
+       [TestFixture]
+       public class LruCacheControllerTest
+       {
+               protected virtual ICacheController GetController() 
+               {
+                       return new LruCacheController();
+               }
+
+               [Test]
+               public virtual void TestSizeOne() 
+               {
+                       ICacheController cc = GetController();
+                       IDictionary props = new HybridDictionary();
+                       props.Add("CacheSize", "1");
+                       cc.Configure(props);
+
+                       string testKey = "testKey";
+                       string testVal = "testVal";
+                       cc[testKey] = testVal;
+                       Assert.AreEqual(testVal, cc[testKey] );
+                       
+                       string testKey2 = "testKey2";
+                       string testVal2 = "testVal2";
+                       cc[testKey2] = testVal2;
+                       Assert.AreEqual(testVal2, cc[testKey2]);
+
+                       Assert.IsNull(cc[testKey]);
+               }
+
+               [Test]
+               public void TestGetAndPutObject() 
+               {
+                       ICacheController cc = GetController();
+                       string testKey = "testKey";
+                       string testVal = "testVal";
+
+                       Assert.AreEqual(cc[testKey], null);
+
+                       cc[testKey] = testVal;
+                       Assert.AreEqual(cc[testKey], testVal);
+
+                       cc[testKey] = null;
+                       Assert.AreEqual(cc[testKey], null);
+               }
+
+               [Test]
+               public void TestRemoveObject() 
+               {
+                       ICacheController cc = GetController();
+                       string testKey = "testKey";
+                       string testVal = "testVal";
+
+                       Assert.AreEqual(cc[testKey], null);
+
+                       cc[testKey] = testVal;
+                       Assert.AreEqual(cc[testKey], testVal);
+
+                       cc.Remove(testKey);
+                       Assert.AreEqual(cc[testKey], null);
+               }
+
+               [Test]
+               public void TestFlush() 
+               {
+                       ICacheController cc = GetController();
+                       string testKey = "testKey";
+                       string testVal = "testVal";
+
+                       Assert.AreEqual(cc[testKey], null);
+
+                       cc[testKey] = testVal;
+                       Assert.AreEqual(cc[testKey], testVal);
+
+                       cc.Flush();
+                       Assert.AreEqual(cc[testKey], null);
+               }
+       }
+}

Added: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheController/MemoryCacheControllerTest.cs
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheController/MemoryCacheControllerTest.cs?rev=353855&view=auto
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheController/MemoryCacheControllerTest.cs
 (added)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheController/MemoryCacheControllerTest.cs
 Sun Dec  4 06:53:40 2005
@@ -0,0 +1,25 @@
+using IBatisNet.DataMapper.Configuration.Cache;
+using IBatisNet.DataMapper.Configuration.Cache.Memory;
+using NUnit.Framework;
+
+namespace IBatisNet.DataMapper.Test.NUnit.SqlMapTests.CacheController
+{
+       /// <summary>
+       /// Description résumée de MemoryCacheControllerTest.
+       /// </summary>
+       [TestFixture]
+       public class MemoryCacheControllerTest: LruCacheControllerTest
+       {
+
+               protected override ICacheController GetController() 
+               {
+                       return new MemoryCacheControler();
+               }
+
+               [Test]
+               public override void TestSizeOne() 
+               {
+                       // This is not relevant for this model
+               }
+       }
+}

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/bin/Debug/SqlMap_PostgreSQL_Npgsql.config
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/bin/Debug/SqlMap_PostgreSQL_Npgsql.config?rev=353855&r1=353854&r2=353855&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/bin/Debug/SqlMap_PostgreSQL_Npgsql.config
 (original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/bin/Debug/SqlMap_PostgreSQL_Npgsql.config
 Sun Dec  4 06:53:40 2005
@@ -14,7 +14,7 @@
        <!-- ==== PostgreSQL configuration =========    -->
        <!-- Rem : If used via a DataAccess context, database tag will be 
ignored -->
        <database>
-               <provider name="PostgreSql0.7.1"/>
+               <provider name="PostgreSql0.7"/>
                <!--
                connectionString=
                Server=127.0.0.1;Port=5432;User 
Id=joe;Password=secret;Database=joedata;

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Cache/Fifo/FifoCacheController.cs
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Cache/Fifo/FifoCacheController.cs?rev=353855&r1=353854&r2=353855&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Cache/Fifo/FifoCacheController.cs
 (original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Cache/Fifo/FifoCacheController.cs
 Sun Dec  4 06:53:40 2005
@@ -25,11 +25,10 @@
 #endregion
 
 #region Imports
+
 using System;
 using System.Collections;
-using System.Collections.Specialized;
 
-using IBatisNet.DataMapper.Configuration.Cache;
 #endregion
 
 namespace IBatisNet.DataMapper.Configuration.Cache.Fifo
@@ -52,23 +51,34 @@
                public FifoCacheController() 
                {
                        _cacheSize = 100;
-                       _cache = new Hashtable();
-                       _keyList = new ArrayList();
+                       _cache = Hashtable.Synchronized( new Hashtable() );
+                       _keyList = ArrayList.Synchronized( new ArrayList() );
                }
                #endregion
 
                #region ICacheController Members
 
                /// <summary>
+               /// Remove an object from a cache model
+               /// </summary>
+               /// <param name="key">the key to the object</param>
+               /// <returns>the removed object(?)</returns>
+               public object Remove(object key)
+               {
+                       object o = this[key];
+
+                       _keyList.Remove(key);
+                       _cache.Remove(key);
+                       return o;
+               }
+
+               /// <summary>
                /// Clears all elements from the cache.
                /// </summary>
                public void Flush()
                {
-                       lock(this) 
-                       {
                                _cache.Clear();
                                _keyList.Clear();
-                       }               
                }
 
 
@@ -81,24 +91,18 @@
                {
                        get
                        {
-                               lock (this) 
-                               {
-                                       return _cache[key];
-                               }
+                               return _cache[key];
                        }
                        set
                        {
-                               lock (this) 
+                               _cache[key] = value;
+                               _keyList.Add(key);
+                               if (_keyList.Count > _cacheSize) 
                                {
-                                       _cache.Add(key, value);
-                                       _keyList.Add(key);
-                                       if (_keyList.Count > _cacheSize) 
-                                       {
-                                               object oldestKey = _keyList[0];
-                                               _keyList.Remove(0);
-                                               _cache.Remove(oldestKey);
-                                       }               
-                               }
+                                       object oldestKey = _keyList[0];
+                                       _keyList.Remove(0);
+                                       _cache.Remove(oldestKey);
+                               }               
                        }
                }
 
@@ -111,7 +115,7 @@
                        string size = (string)properties["CacheSize"];;
                        if (size != null) 
                        {
-                               _cacheSize = System.Convert.ToInt32(size);      
        
+                               _cacheSize = Convert.ToInt32(size);             
                        }
                }
                

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Cache/ICacheController.cs
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Cache/ICacheController.cs?rev=353855&r1=353854&r2=353855&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Cache/ICacheController.cs
 (original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Cache/ICacheController.cs
 Sun Dec  4 06:53:40 2005
@@ -51,6 +51,14 @@
                #endregion
 
                #region Methods
+       
+               /// <summary>
+               /// Remove an object from a cache model
+               /// </summary>
+               /// <param name="key">the key to the object</param>
+               /// <returns>the removed object(?)</returns>
+               object Remove(object key);
+
                /// <summary>
                /// Clears all elements from the cache.
                /// </summary>

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Cache/Lru/LruCacheController.cs
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Cache/Lru/LruCacheController.cs?rev=353855&r1=353854&r2=353855&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Cache/Lru/LruCacheController.cs
 (original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Cache/Lru/LruCacheController.cs
 Sun Dec  4 06:53:40 2005
@@ -25,11 +25,10 @@
 #endregion
 
 #region Imports
+
 using System;
 using System.Collections;
-using System.Collections.Specialized;
 
-using IBatisNet.DataMapper.Configuration.Cache;
 #endregion
 
 namespace IBatisNet.DataMapper.Configuration.Cache.Lru
@@ -52,23 +51,34 @@
                public LruCacheController() 
                {
                        _cacheSize = 100;
-                       _cache = new Hashtable();
-                       _keyList = new ArrayList();
+                       _cache = Hashtable.Synchronized( new Hashtable() );
+                       _keyList = ArrayList.Synchronized( new ArrayList() );
                }
                #endregion
 
                #region ICacheController Members
 
                /// <summary>
+               /// Remove an object from a cache model
+               /// </summary>
+               /// <param name="key">the key to the object</param>
+               /// <returns>the removed object(?)</returns>
+               public object Remove(object key)
+               {
+                       object o = this[key];
+
+                       _keyList.Remove(key);
+                       _cache.Remove(key);
+                       return o;
+               }
+
+               /// <summary>
                /// Clears all elements from the cache.
                /// </summary>
                public void Flush()
                {
-                       lock(this) 
-                       {
-                               _cache.Clear();
-                               _keyList.Clear();
-                       }                               
+                       _cache.Clear();
+                       _keyList.Clear();       
                }
 
 
@@ -77,29 +87,23 @@
                /// Gets a cached object with the specified key.
                /// </summary>
                /// <value>The cached object or <c>null</c></value>
-               public object this [object key] 
+               public object this[object key] 
                {
                        get
                        {
-                               lock (this) 
-                               {
-                                       _keyList.Remove(key);
-                                       _keyList.Add(key);
-                                       return _cache[key];
-                               }
+                               _keyList.Remove(key);
+                               _keyList.Add(key);
+                               return _cache[key];
                        }
                        set
                        {
-                               lock (this) 
+                               _cache[key] = value;
+                               _keyList.Add(key);
+                               if (_keyList.Count > _cacheSize) 
                                {
-                                       _cache.Add(key, value);
-                                       _keyList.Add(key);
-                                       if (_keyList.Count > _cacheSize) 
-                                       {
-                                               object oldestKey = _keyList[0];
-                                               _keyList.Remove(0);
-                                               _cache.Remove(oldestKey);
-                                       }               
+                                       object oldestKey = _keyList[0];
+                                       _keyList.Remove(0);
+                                       _cache.Remove(oldestKey);
                                }               
                        }
                }
@@ -113,7 +117,7 @@
                        string size = (string)properties["CacheSize"];;
                        if (size != null) 
                        {
-                               _cacheSize = System.Convert.ToInt32(size);      
        
+                               _cacheSize = Convert.ToInt32(size);             
                        }               
                }
 

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Cache/Memory/MemoryCacheControler.cs
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Cache/Memory/MemoryCacheControler.cs?rev=353855&r1=353854&r2=353855&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Cache/Memory/MemoryCacheControler.cs
 (original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Cache/Memory/MemoryCacheControler.cs
 Sun Dec  4 06:53:40 2005
@@ -25,11 +25,10 @@
 #endregion
 
 #region Imports
+
 using System;
 using System.Collections;
-using System.Collections.Specialized;
 
-using IBatisNet.DataMapper.Configuration.Cache;
 #endregion
 
 namespace IBatisNet.DataMapper.Configuration.Cache.Memory
@@ -50,13 +49,36 @@
                /// </summary>
                public MemoryCacheControler() 
                {
-                       _cache = new Hashtable();
+                       _cache = Hashtable.Synchronized( new Hashtable() );
                }
                #endregion
 
                #region ICacheController Members
 
                /// <summary>
+               /// Remove an object from a cache model
+               /// </summary>
+               /// <param name="key">the key to the object</param>
+               /// <returns>the removed object(?)</returns>
+               public object Remove(object key)
+               {
+                       object value = null;
+                       object reference = this[key];
+                       _cache.Remove(key);
+                       if (reference != null) 
+                       {
+                               if (reference is StrongReference) 
+                               {
+                                       value = ((StrongReference) 
reference).Target;
+                               } 
+                               else if (reference is WeakReference) {
+                                       value = ((WeakReference) 
reference).Target;
+                               }
+                       }
+                       return value;
+               }
+
+               /// <summary>
                /// Adds an item with the specified key and value into cached 
data.
                /// Gets a cached object with the specified key.
                /// </summary>
@@ -65,39 +87,34 @@
                {
                        get
                        {
-                               lock (this) 
+                               object value = null;
+                               object reference = _cache[key];
+                               if (reference != null) 
                                {
-                                       object value = null;
-                                       object reference = _cache[key];
-                                       if (reference != null) 
+                                       if (reference is StrongReference) 
                                        {
-                                               if (reference is 
StrongReference) 
-                                               {
-                                                       value = 
((StrongReference) reference).Target;
-                                               } 
-                                               else if (reference is 
WeakReference) 
-                                               {
-                                                       value = 
((WeakReference) reference).Target;
-                                               }
-                                       }                               
-                                       return value;
-                               }
+                                               value = ((StrongReference) 
reference).Target;
+                                       } 
+                                       else if (reference is WeakReference) 
+                                       {
+                                               value = ((WeakReference) 
reference).Target;
+                                       }
+                               }                               
+                               return value;
                        }
                        set
                        {
-                               lock (this) 
+                               object reference = null;
+                               if (_cacheLevel.Equals(MemoryCacheLevel.Weak)) 
                                {
-                                       object reference = null;
-                                       if 
(_cacheLevel.Equals(MemoryCacheLevel.Weak)) 
-                                       {
-                                               reference = new 
WeakReference(value);
-                                       } 
-                                       else if 
(_cacheLevel.Equals(MemoryCacheLevel.Strong)) 
-                                       {
-                                               reference = new 
StrongReference(value);
-                                       }
-                                       _cache[key] = reference;        
-                               }                       
+                                       reference = new WeakReference(value);
+                               } 
+                               else if 
(_cacheLevel.Equals(MemoryCacheLevel.Strong)) 
+                               {
+                                       reference = new StrongReference(value);
+                               }
+                               _cache[key] = reference;        
+                       
                        }
                }
 


Reply via email to