29 using System.Collections;
30 using System.Collections.Generic;
31 using System.Threading;
33 namespace OpenSim.Framework
50 public class CnmSynchronizedCache<TKey, TValue> : ICnmCache<TKey, TValue>
60 private readonly
object m_syncRoot;
72 m_syncRoot = m_cache.SyncRoot;
90 throw new ArgumentNullException(
"cache");
94 #region Nested type: SynchronizedEnumerator
99 private class SynchronizedEnumerator : IEnumerator<KeyValuePair<TKey, TValue>>
104 private readonly IEnumerator<KeyValuePair<TKey, TValue>> m_enumerator;
109 private object m_syncRoot;
120 public SynchronizedEnumerator(IEnumerator<KeyValuePair<TKey, TValue>> enumerator,
object syncRoot)
122 m_syncRoot = syncRoot;
123 m_enumerator = enumerator;
124 Monitor.Enter(m_syncRoot);
130 ~SynchronizedEnumerator()
135 #region IEnumerator<KeyValuePair<TKey,TValue>> Members
146 public KeyValuePair<TKey, TValue> Current
148 get {
return m_enumerator.Current; }
160 object IEnumerator.Current
162 get {
return Current; }
168 public void Dispose()
170 if (m_syncRoot != null)
172 Monitor.Exit(m_syncRoot);
176 m_enumerator.Dispose();
177 GC.SuppressFinalize(
this);
189 public bool MoveNext()
191 return m_enumerator.MoveNext();
202 m_enumerator.Reset();
210 #region ICnmCache<TKey,TValue> Members
231 return m_cache.Count;
271 public TimeSpan ExpirationTime
277 return m_cache.ExpirationTime;
285 m_cache.ExpirationTime = value;
307 public bool IsCountLimited
313 return m_cache.IsCountLimited;
336 public bool IsSizeLimited
342 return m_cache.IsSizeLimited;
363 public bool IsSynchronized
385 public bool IsTimeLimited
391 return m_cache.IsTimeLimited;
415 return m_cache.MaxCount;
423 m_cache.MaxCount = value;
444 public long MaxElementSize
450 return m_cache.MaxElementSize;
480 return m_cache.MaxSize;
488 m_cache.MaxSize = value;
542 public object SyncRoot
544 get {
return m_syncRoot; }
574 return new SynchronizedEnumerator(m_cache.GetEnumerator(), m_syncRoot);
601 m_cache.PurgeExpired();
645 m_cache.RemoveRange(keys);
694 public bool Set(TKey
key, TValue value,
long size)
698 return m_cache.Set(
key, value, size);
729 return m_cache.TryGetValue(
key, out value);
740 IEnumerator IEnumerable.GetEnumerator()
742 return GetEnumerator();
IEnumerator< KeyValuePair< TKey, TValue > > GetEnumerator()
Returns an enumerator that iterates through the elements stored to ICnmCache{TKey,TValue}.
static ICnmCache< TKey, TValue > Synchronized(ICnmCache< TKey, TValue > cache)
Returns a ICnmCache{TKey,TValue} wrapper that is synchronized (thread safe).
bool TryGetValue(TKey key, out TValue value)
Gets the value associated with the specified key .
Synchronized Cenome cache wrapper.
void Remove(TKey key)
Removes element associated with key from the ICnmCache{TKey,TValue}.
void RemoveRange(IEnumerable< TKey > keys)
Removes elements that are associated with one of keys from the ICnmCache{TKey,TValue}.
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString key
void Clear()
Removes all elements from the ICnmCache{TKey,TValue}.
void PurgeExpired()
Purge expired elements from the ICnmCache{TKey,TValue}.
System.Collections.IEnumerable IEnumerable
bool Set(TKey key, TValue value, long size)
Add or replace an element with the provided key , value and size to ICnmCache{TKey,TValue}.
Represent generic cache to store key/value pairs (elements) limited by time, size and count of elemen...