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