Lucene.Net  3.0.3
Lucene.Net is a .NET port of the Java Lucene Indexing Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties
Cache.cs
Go to the documentation of this file.
1 /*
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
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17 
18 using System;
19 
20 namespace Lucene.Net.Util.Cache
21 {
22 
23 
25  public abstract class Cache<TKey, TValue> : IDisposable
26  {
27 
31  internal class SynchronizedCache_Renamed_Class : Cache<TKey, TValue>
32  {
33  internal System.Object mutex;
34  internal Cache<TKey,TValue> cache;
35 
36  internal SynchronizedCache_Renamed_Class(Cache<TKey, TValue> cache)
37  {
38  this.cache = cache;
39  this.mutex = this;
40  }
41 
42  internal SynchronizedCache_Renamed_Class(Cache<TKey, TValue> cache, System.Object mutex)
43  {
44  this.cache = cache;
45  this.mutex = mutex;
46  }
47 
48  public override void Put(TKey key, TValue value_Renamed)
49  {
50  lock (mutex)
51  {
52  cache.Put(key, value_Renamed);
53  }
54  }
55 
56  public override TValue Get(System.Object key)
57  {
58  lock (mutex)
59  {
60  return cache.Get(key);
61  }
62  }
63 
64  public override bool ContainsKey(System.Object key)
65  {
66  lock (mutex)
67  {
68  return cache.ContainsKey(key);
69  }
70  }
71 
72  protected override void Dispose(bool disposing)
73  {
74  lock (mutex)
75  {
76  cache.Dispose();
77  }
78  }
79 
80  internal override Cache<TKey,TValue> GetSynchronizedCache()
81  {
82  return this;
83  }
84  }
85 
90  public static Cache<TKey, TValue> SynchronizedCache(Cache<TKey, TValue> cache)
91  {
92  return cache.GetSynchronizedCache();
93  }
94 
101  internal virtual Cache<TKey, TValue> GetSynchronizedCache()
102  {
103  return new SynchronizedCache_Renamed_Class(this);
104  }
105 
107  public abstract void Put(TKey key, TValue value_Renamed);
108 
110  public abstract TValue Get(System.Object key);
111 
113  public abstract bool ContainsKey(System.Object key);
114 
116  [Obsolete("Use Dispose() instead")]
117  public void Close()
118  {
119  Dispose();
120  }
121 
122  public void Dispose()
123  {
124  Dispose(true);
125  }
126 
127  protected abstract void Dispose(bool disposing);
128  }
129 }