Modified:
branches/5.1/CHANGES
branches/5.1/Driver/Source/Connection.cs
branches/5.1/Driver/Source/MySqlConnectionStringBuilder.cs
branches/5.1/Driver/Source/common/Cache.cs
Log:
- Incorporated some connection string cache optimizations sent to us by Maxim Mass (bug
#34000)
Modified: branches/5.1/CHANGES
===================================================================
--- branches/5.1/CHANGES 2008-01-29 15:41:41 UTC (rev 1152)
+++ branches/5.1/CHANGES 2008-01-29 16:32:12 UTC (rev 1153)
@@ -5,6 +5,7 @@
- Fixed nant compilation problem on mono (bug #33508)
- Fixed problem where connection state reported through the state change handler was
not
showing Open (bug #34082)
+ - Incorporated some connection string cache optimizations sent to us by Maxim Mass (bug
#34000)
Version 5.1.4 - 11/12/2007
- Fixed issue where column name metadata was not using the charset given on the
connection string
Modified: branches/5.1/Driver/Source/Connection.cs
===================================================================
--- branches/5.1/Driver/Source/Connection.cs 2008-01-29 15:41:41 UTC (rev 1152)
+++ branches/5.1/Driver/Source/Connection.cs 2008-01-29 16:32:12 UTC (rev 1153)
@@ -59,7 +59,8 @@
/// <include file='docs/MySqlConnection.xml' path='docs/InfoMessage/*'/>
public event MySqlInfoMessageEventHandler InfoMessage;
- private static Cache connectionStringCache = new Cache(0, 25);
+ private static Cache<string, MySqlConnectionStringBuilder>
connectionStringCache =
+ new Cache<string, MySqlConnectionStringBuilder>(0, 25);
/// <include file='docs/MySqlConnection.xml' path='docs/DefaultCtor/*'/>
public MySqlConnection()
Modified: branches/5.1/Driver/Source/MySqlConnectionStringBuilder.cs
===================================================================
--- branches/5.1/Driver/Source/MySqlConnectionStringBuilder.cs 2008-01-29 15:41:41 UTC
(rev 1152)
+++ branches/5.1/Driver/Source/MySqlConnectionStringBuilder.cs 2008-01-29 16:32:12 UTC
(rev 1153)
@@ -957,8 +957,8 @@
persistConnString.Remove(0, persistConnString.Length);
// set all the proper defaults
- foreach (Keyword k in defaultValues.Keys)
- SetValue(k, defaultValues[k]);
+ foreach (KeyValuePair<Keyword, object> k in defaultValues)
+ SetValue(k.Key, k.Value);
}
private static Keyword GetKey(string key)
Modified: branches/5.1/Driver/Source/common/Cache.cs
===================================================================
--- branches/5.1/Driver/Source/common/Cache.cs 2008-01-29 15:41:41 UTC (rev 1152)
+++ branches/5.1/Driver/Source/common/Cache.cs 2008-01-29 16:32:12 UTC (rev 1153)
@@ -18,42 +18,59 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using System.Collections.Specialized;
using System;
+using System.Collections.Generic;
namespace MySql.Data.Common
{
- internal class Cache : NameObjectCollectionBase
- {
- private int capacity;
+ internal class Cache<KeyType, ValueType>
+ {
+ private int _capacity;
+ private Queue<KeyType> _keyQ;
+ private Dictionary<KeyType, ValueType> _contents;
- public Cache(int initialCapacity, int capacity) :
- base(initialCapacity, StringComparer.CurrentCulture)
- {
- this.capacity = capacity;
- }
+ public Cache(int initialCapacity, int capacity)
+ {
+ _capacity = capacity;
+ _contents = new Dictionary<KeyType, ValueType>(initialCapacity);
- public object this[string key]
- {
- get { return BaseGet(key); }
- set { InternalAdd(key, value); }
- }
+ if (capacity > 0)
+ _keyQ = new Queue<KeyType>(initialCapacity);
+ }
- public void Add(string key, object value)
- {
- InternalAdd(key, value);
- }
+ public ValueType this[KeyType key]
+ {
+ get
+ {
+ ValueType val;
+ if (_contents.TryGetValue(key, out val))
+ return val;
+ else
+ return default(ValueType);
+ }
+ set { InternalAdd(key, value); }
+ }
- private void InternalAdd(string key, object value)
- {
- if (base.Count == capacity)
- RemoveOldestItem();
- BaseAdd(key, value);
- }
+ public void Add(KeyType key, ValueType value)
+ {
+ InternalAdd(key, value);
+ }
- private void RemoveOldestItem()
- {
- BaseRemoveAt(0);
- }
- }
-}
\ No newline at end of file
+ private void InternalAdd(KeyType key, ValueType value)
+ {
+ if (!_contents.ContainsKey(key))
+ {
+
+ if (_capacity > 0)
+ {
+ _keyQ.Enqueue(key);
+
+ if (_keyQ.Count > _capacity)
+ _contents.Remove(_keyQ.Dequeue());
+ }
+ }
+
+ _contents[key] = value;
+ }
+ }
+}
| Thread |
|---|
| • Connector/NET commit: r1153 - in branches/5.1: . Driver/Source Driver/Source/common | rburnett | 29 Jan 2008 |