1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.Facilities
.Cache
.Tests
17 using System
.Collections
;
18 using System
.Collections
.Specialized
;
19 using Castle
.Facilities
.Cache
.Manager
;
22 /// Description résumée de FifoCacheManager.
24 public class FifoCacheManager
: ICacheManager
27 private int _cacheSize
= 0;
28 private IDictionary _cache
= null;
29 private IList _keyList
= null;
30 private ICacheKeyGenerator _cacheKeyGenerator
= null;
35 get { return _keyList; }
38 #region Constructor (s) / Destructor
42 public FifoCacheManager(int cacheSize
)
44 _cacheSize
= cacheSize
;
45 _cache
= new HybridDictionary();
46 _keyList
= new ArrayList();
50 #region ICacheManager Members
53 /// A generator of keys for a cache entry.
55 public ICacheKeyGenerator CacheKeyGenerator
57 get { return _cacheKeyGenerator; }
58 set { _cacheKeyGenerator = value; }
62 /// Clears all elements from the cache.
75 /// Adds an item with the specified key and value into cached data.
76 /// Gets a cached object with the specified key.
78 /// <value>The cached object or <c>null</c></value>
79 public object this [object key
]
92 _cache
.Add(key
, value);
94 if (_keyList
.Count
> _cacheSize
)
96 object oldestKey
= _keyList
[0];
98 _cache
.Remove(oldestKey
);