2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
20 namespace Mono.Lucene.Net.Util.Cache
23 /// <summary> Simple cache implementation that uses a HashMap to store (key, value) pairs.
24 /// This cache is not synchronized, use {@link Cache#SynchronizedCache(Cache)}
27 public class SimpleMapCache:Cache
29 internal System.Collections.IDictionary map;
31 public SimpleMapCache():this(new System.Collections.Hashtable())
35 public SimpleMapCache(System.Collections.IDictionary map)
40 public override System.Object Get(System.Object key)
45 public override void Put(System.Object key, System.Object value_Renamed)
47 map[key] = value_Renamed;
50 public override void Close()
55 public override bool ContainsKey(System.Object key)
57 return map.Contains(key);
60 /// <summary> Returns a Set containing all keys in this cache.</summary>
61 public virtual System.Collections.ICollection KeySet()
66 internal override Cache GetSynchronizedCache()
68 return new SynchronizedSimpleMapCache(this);
71 private class SynchronizedSimpleMapCache:SimpleMapCache
73 internal System.Object mutex;
74 internal SimpleMapCache cache;
76 internal SynchronizedSimpleMapCache(SimpleMapCache cache)
82 public override void Put(System.Object key, System.Object value_Renamed)
86 cache.Put(key, value_Renamed);
90 public override System.Object Get(System.Object key)
94 return cache.Get(key);
98 public override bool ContainsKey(System.Object key)
102 return cache.ContainsKey(key);
106 public override void Close()
114 public override System.Collections.ICollection KeySet()
118 return cache.KeySet();
122 internal override Cache GetSynchronizedCache()