1 // created on 29/11/2007
\r
3 // Npgsql.NpgsqlConnectionStringBuilder.cs
\r
6 // Glen Parker (glenebob@nwlink.com)
\r
7 // Ben Sagal (bensagal@gmail.com)
\r
8 // Tao Wang (dancefire@gmail.com)
\r
10 // Copyright (C) 2007 The Npgsql Development Team
\r
11 // npgsql-general@gborg.postgresql.org
\r
12 // http://gborg.postgresql.org/project/npgsql/projdisplay.php
\r
14 // Permission to use, copy, modify, and distribute this software and its
\r
15 // documentation for any purpose, without fee, and without a written
\r
16 // agreement is hereby granted, provided that the above copyright notice
\r
17 // and this paragraph and the following two paragraphs appear in all copies.
\r
19 // IN NO EVENT SHALL THE NPGSQL DEVELOPMENT TEAM BE LIABLE TO ANY PARTY
\r
20 // FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
\r
21 // INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
\r
22 // DOCUMENTATION, EVEN IF THE NPGSQL DEVELOPMENT TEAM HAS BEEN ADVISED OF
\r
23 // THE POSSIBILITY OF SUCH DAMAGE.
\r
25 // THE NPGSQL DEVELOPMENT TEAM SPECIFICALLY DISCLAIMS ANY WARRANTIES,
\r
26 // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
\r
27 // AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
\r
28 // ON AN "AS IS" BASIS, AND THE NPGSQL DEVELOPMENT TEAM HAS NO OBLIGATIONS
\r
29 // TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
\r
32 using System.Collections.Generic;
\r
33 //using System.Text;
\r
37 internal class Cache<TEntity> : LinkedList<KeyValuePair<string, TEntity>>
\r
38 where TEntity : class
\r
40 private int _cache_size = 20;
\r
43 /// Set Cache Size. The default value is 20.
\r
45 public int CacheSize
\r
47 get { return _cache_size; }
\r
50 if (value < 0) { throw new ArgumentOutOfRangeException("CacheSize"); }
\r
52 _cache_size = value;
\r
54 if (this.Count > _cache_size)
\r
58 while (_cache_size < this.Count)
\r
68 /// Lookup cached entity. null will returned if not match.
\r
69 /// For both get{} and set{} apply LRU rule.
\r
71 /// <param name="key">key</param>
\r
72 /// <returns></returns>
\r
73 public TEntity this[string key]
\r
79 for (LinkedListNode<KeyValuePair<string, TEntity>> node = this.First; node != null; node = node.Next)
\r
81 if (node.Value.Key == key)
\r
84 this.AddFirst(node);
\r
85 return node.Value.Value;
\r
95 for (LinkedListNode<KeyValuePair<string, TEntity>> node = this.First; node != null; node = node.Next)
\r
97 if (node.Value.Key == key)
\r
100 this.AddFirst(node);
\r
104 if (this.CacheSize > 0)
\r
106 this.AddFirst(new KeyValuePair<string, TEntity>(key, value));
\r
107 if (this.Count > this.CacheSize)
\r
116 public Cache() : base() { }
\r
117 public Cache(int cacheSize) : base()
\r
119 this._cache_size = cacheSize;
\r