| |||||||||||||||||
Source File | Conditionals | Statements | Methods | TOTAL | |||||||||||||
Configuration\Cache\Fifo\FifoCacheController.cs | 0.0 % | 0.0 % | 0.0 % | 0.0 % |
|
1 | ||
2 | #region Apache Notice | |
3 | /***************************************************************************** | |
4 | * $Header: $ | |
5 | * $Revision: $ | |
6 | * $Date: $ | |
7 | * | |
8 | * iBATIS.NET Data Mapper | |
9 | * Copyright (C) 2004 - Gilles Bayon | |
10 | * | |
11 | * | |
12 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
13 | * you may not use this file except in compliance with the License. | |
14 | * You may obtain a copy of the License at | |
15 | * | |
16 | * http://www.apache.org/licenses/LICENSE-2.0 | |
17 | * | |
18 | * Unless required by applicable law or agreed to in writing, software | |
19 | * distributed under the License is distributed on an "AS IS" BASIS, | |
20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
21 | * See the License for the specific language governing permissions and | |
22 | * limitations under the License. | |
23 | * | |
24 | ********************************************************************************/ | |
25 | #endregion | |
26 | ||
27 | #region Imports | |
28 | using System; | |
29 | using System.Collections; | |
30 | using System.Collections.Specialized; | |
31 | ||
32 | using IBatisNet.DataMapper.Configuration.Cache; | |
33 | #endregion | |
34 | ||
35 | namespace IBatisNet.DataMapper.Configuration.Cache.Fifo | |
36 | { | |
37 | /// <summary> | |
38 | /// Summary description for FifoCacheController. | |
39 | /// </summary> | |
40 | public class FifoCacheController : ICacheController | |
41 | { | |
42 | #region Fields | |
43 | private int _cacheSize = 0; | |
44 | private Hashtable _cache = null; | |
45 | private IList _keyList = null; | |
46 | #endregion | |
47 | ||
48 | #region Constructor (s) / Destructor | |
49 | /// <summary> | |
50 | /// | |
51 | /// </summary> | |
52 | 0 | public FifoCacheController() |
53 | { | |
54 | _cacheSize = 100; | |
55 | _cache = new Hashtable(); | |
56 | _keyList = new ArrayList(); | |
57 | } | |
58 | #endregion | |
59 | ||
60 | #region ICacheController Members | |
61 | ||
62 | /// <summary> | |
63 | /// Clears all elements from the cache. | |
64 | /// </summary> | |
65 | 0 | public void Flush() |
66 | { | |
67 | lock(this) | |
68 | { | |
69 | _cache.Clear(); | |
70 | _keyList.Clear(); | |
71 | } | |
72 | } | |
73 | ||
74 | ||
75 | /// <summary> | |
76 | /// Adds an item with the specified key and value into cached data. | |
77 | /// Gets a cached object with the specified key. | |
78 | /// </summary> | |
79 | /// <value>The cached object or <c>null</c></value> | |
80 | 0 | public object this [object key] |
81 | { | |
82 | get | |
83 | { | |
84 | lock (this) | |
85 | { | |
86 | return _cache[key]; | |
87 | } | |
88 | } | |
89 | set | |
90 | { | |
91 | lock (this) | |
92 | { | |
93 | _cache.Add(key, value); | |
94 | _keyList.Add(key); | |
95 | if (_keyList.Count > _cacheSize) | |
96 | { | |
97 | object oldestKey = _keyList[0]; | |
98 | _keyList.Remove(0); | |
99 | _cache.Remove(oldestKey); | |
100 | } | |
101 | } | |
102 | } | |
103 | } | |
104 | ||
105 | ||
106 | /// <summary> | |
107 | /// Configures the cache | |
108 | /// </summary> | |
109 | 0 | public void Configure(HybridDictionary properties) |
110 | { | |
111 | string size = (string)properties["CacheSize"];; | |
112 | if (size != null) | |
113 | { | |
114 | _cacheSize = System.Convert.ToInt32(size); | |
115 | } | |
116 | } | |
117 | ||
118 | #endregion | |
119 | ||
120 | } | |
121 | } | |
122 |
|