aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/CnmMemoryCache.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/CnmMemoryCache.cs')
-rw-r--r--OpenSim/Framework/CnmMemoryCache.cs246
1 files changed, 123 insertions, 123 deletions
diff --git a/OpenSim/Framework/CnmMemoryCache.cs b/OpenSim/Framework/CnmMemoryCache.cs
index 77ca10c..db91801 100644
--- a/OpenSim/Framework/CnmMemoryCache.cs
+++ b/OpenSim/Framework/CnmMemoryCache.cs
@@ -81,7 +81,7 @@ namespace OpenSim.Framework
81 /// 30 minutes. 81 /// 30 minutes.
82 /// </para> 82 /// </para>
83 /// </remarks> 83 /// </remarks>
84 public static readonly TimeSpan DefaultExpirationTime = TimeSpan.FromMinutes( 30.0 ); 84 public static readonly TimeSpan DefaultExpirationTime = TimeSpan.FromMinutes(30.0);
85 85
86 /// <summary> 86 /// <summary>
87 /// Minimal allowed expiration time. 87 /// Minimal allowed expiration time.
@@ -91,7 +91,7 @@ namespace OpenSim.Framework
91 /// 5 minutes. 91 /// 5 minutes.
92 /// </para> 92 /// </para>
93 /// </remarks> 93 /// </remarks>
94 public static readonly TimeSpan MinExpirationTime = TimeSpan.FromSeconds( 10.0 ); 94 public static readonly TimeSpan MinExpirationTime = TimeSpan.FromSeconds(10.0);
95 95
96 /// <summary> 96 /// <summary>
97 /// Comparer used to compare element keys. 97 /// Comparer used to compare element keys.
@@ -171,7 +171,7 @@ namespace OpenSim.Framework
171 /// Initializes a new instance of the <see cref="CnmMemoryCache{TKey,TValue}"/> class. 171 /// Initializes a new instance of the <see cref="CnmMemoryCache{TKey,TValue}"/> class.
172 /// </summary> 172 /// </summary>
173 public CnmMemoryCache() 173 public CnmMemoryCache()
174 : this( DefaultMaxSize ) 174 : this(DefaultMaxSize)
175 { 175 {
176 } 176 }
177 177
@@ -181,8 +181,8 @@ namespace OpenSim.Framework
181 /// <param name="maximalSize"> 181 /// <param name="maximalSize">
182 /// Maximal cache size. 182 /// Maximal cache size.
183 /// </param> 183 /// </param>
184 public CnmMemoryCache( long maximalSize ) 184 public CnmMemoryCache(long maximalSize)
185 : this( maximalSize, DefaultMaxCount ) 185 : this(maximalSize, DefaultMaxCount)
186 { 186 {
187 } 187 }
188 188
@@ -195,8 +195,8 @@ namespace OpenSim.Framework
195 /// <param name="maximalCount"> 195 /// <param name="maximalCount">
196 /// Maximal element count. 196 /// Maximal element count.
197 /// </param> 197 /// </param>
198 public CnmMemoryCache( long maximalSize, int maximalCount ) 198 public CnmMemoryCache(long maximalSize, int maximalCount)
199 : this( maximalSize, maximalCount, DefaultExpirationTime ) 199 : this(maximalSize, maximalCount, DefaultExpirationTime)
200 { 200 {
201 } 201 }
202 202
@@ -212,8 +212,8 @@ namespace OpenSim.Framework
212 /// <param name="expirationTime"> 212 /// <param name="expirationTime">
213 /// Elements expiration time. 213 /// Elements expiration time.
214 /// </param> 214 /// </param>
215 public CnmMemoryCache( long maximalSize, int maximalCount, TimeSpan expirationTime ) 215 public CnmMemoryCache(long maximalSize, int maximalCount, TimeSpan expirationTime)
216 : this( maximalSize, maximalCount, expirationTime, EqualityComparer<TKey>.Default ) 216 : this(maximalSize, maximalCount, expirationTime, EqualityComparer<TKey>.Default)
217 { 217 {
218 } 218 }
219 219
@@ -235,21 +235,21 @@ namespace OpenSim.Framework
235 /// <exception cref="ArgumentNullException"> 235 /// <exception cref="ArgumentNullException">
236 /// <see cref="comparer"/>is <see langword="null"/> reference. 236 /// <see cref="comparer"/>is <see langword="null"/> reference.
237 /// </exception> 237 /// </exception>
238 public CnmMemoryCache( long maximalSize, 238 public CnmMemoryCache(long maximalSize,
239 int maximalCount, 239 int maximalCount,
240 TimeSpan expirationTime, 240 TimeSpan expirationTime,
241 IEqualityComparer<TKey> comparer ) 241 IEqualityComparer<TKey> comparer)
242 { 242 {
243 if( comparer == null ) 243 if (comparer == null)
244 throw new ArgumentNullException( "comparer" ); 244 throw new ArgumentNullException("comparer");
245 245
246 if( expirationTime < MinExpirationTime ) 246 if (expirationTime < MinExpirationTime)
247 expirationTime = MinExpirationTime; 247 expirationTime = MinExpirationTime;
248 if( maximalCount < 8 ) 248 if (maximalCount < 8)
249 maximalCount = 8; 249 maximalCount = 8;
250 if( maximalSize < 8 ) 250 if (maximalSize < 8)
251 maximalSize = 8; 251 maximalSize = 8;
252 if( maximalCount > maximalSize ) 252 if (maximalCount > maximalSize)
253 maximalCount = (int) maximalSize; 253 maximalCount = (int) maximalSize;
254 254
255 Comparer = comparer; 255 Comparer = comparer;
@@ -275,14 +275,14 @@ namespace OpenSim.Framework
275 /// <param name="size"> 275 /// <param name="size">
276 /// The element's size. 276 /// The element's size.
277 /// </param> 277 /// </param>
278 protected virtual void AddToNewGeneration( int bucketIndex, TKey key, TValue value, long size ) 278 protected virtual void AddToNewGeneration(int bucketIndex, TKey key, TValue value, long size)
279 { 279 {
280 // Add to newest generation 280 // Add to newest generation
281 if( !m_newGeneration.Set( bucketIndex, key, value, size ) ) 281 if (!m_newGeneration.Set(bucketIndex, key, value, size))
282 { 282 {
283 // Failed to add new generation 283 // Failed to add new generation
284 RecycleGenerations(); 284 RecycleGenerations();
285 m_newGeneration.Set( bucketIndex, key, value, size ); 285 m_newGeneration.Set(bucketIndex, key, value, size);
286 } 286 }
287 287
288 m_version++; 288 m_version++;
@@ -314,9 +314,9 @@ namespace OpenSim.Framework
314 /// For example: key's hash is 72, bucket count is 5, element's bucket index is 72 % 5 = 2. 314 /// For example: key's hash is 72, bucket count is 5, element's bucket index is 72 % 5 = 2.
315 /// </para> 315 /// </para>
316 /// </remarks> 316 /// </remarks>
317 protected virtual int GetBucketIndex( TKey key ) 317 protected virtual int GetBucketIndex(TKey key)
318 { 318 {
319 return (Comparer.GetHashCode( key ) & 0x7FFFFFFF) % m_generationBucketCount; 319 return (Comparer.GetHashCode(key) & 0x7FFFFFFF) % m_generationBucketCount;
320 } 320 }
321 321
322 /// <summary> 322 /// <summary>
@@ -325,7 +325,7 @@ namespace OpenSim.Framework
325 /// <param name="generation"> 325 /// <param name="generation">
326 /// The generation that is purged. 326 /// The generation that is purged.
327 /// </param> 327 /// </param>
328 protected virtual void PurgeGeneration( IGeneration generation ) 328 protected virtual void PurgeGeneration(IGeneration generation)
329 { 329 {
330 generation.Clear(); 330 generation.Clear();
331 m_version++; 331 m_version++;
@@ -339,7 +339,7 @@ namespace OpenSim.Framework
339 // Do this only one in every m_operationsBetweenTimeChecks 339 // Do this only one in every m_operationsBetweenTimeChecks
340 // Fetching time is using several millisecons - it is better not to do all time. 340 // Fetching time is using several millisecons - it is better not to do all time.
341 m_operationsBetweenTimeChecks--; 341 m_operationsBetweenTimeChecks--;
342 if( m_operationsBetweenTimeChecks <= 0 ) 342 if (m_operationsBetweenTimeChecks <= 0)
343 PurgeExpired(); 343 PurgeExpired();
344 } 344 }
345 345
@@ -355,10 +355,10 @@ namespace OpenSim.Framework
355 m_generationElementCount = MaxCount / 2; 355 m_generationElementCount = MaxCount / 2;
356 356
357 // Buckets need to be prime number to get better spread of hash values 357 // Buckets need to be prime number to get better spread of hash values
358 m_generationBucketCount = PrimeNumberHelper.GetPrime( m_generationElementCount ); 358 m_generationBucketCount = PrimeNumberHelper.GetPrime(m_generationElementCount);
359 359
360 m_newGeneration = new HashGeneration( this ); 360 m_newGeneration = new HashGeneration(this);
361 m_oldGeneration = new HashGeneration( this ); 361 m_oldGeneration = new HashGeneration(this);
362 m_oldGeneration.MakeOld(); 362 m_oldGeneration.MakeOld();
363 } 363 }
364 364
@@ -399,7 +399,7 @@ namespace OpenSim.Framework
399 /// <param name="cache"> 399 /// <param name="cache">
400 /// The cache. 400 /// The cache.
401 /// </param> 401 /// </param>
402 public Enumerator( CnmMemoryCache<TKey, TValue> cache ) 402 public Enumerator(CnmMemoryCache<TKey, TValue> cache)
403 { 403 {
404 m_generationEnumerators[ 0 ] = cache.m_newGeneration.GetEnumerator(); 404 m_generationEnumerators[ 0 ] = cache.m_newGeneration.GetEnumerator();
405 m_generationEnumerators[ 1 ] = cache.m_oldGeneration.GetEnumerator(); 405 m_generationEnumerators[ 1 ] = cache.m_oldGeneration.GetEnumerator();
@@ -420,7 +420,7 @@ namespace OpenSim.Framework
420 { 420 {
421 get 421 get
422 { 422 {
423 if( m_currentEnumerator == -1 || m_currentEnumerator >= m_generationEnumerators.Length ) 423 if (m_currentEnumerator == -1 || m_currentEnumerator >= m_generationEnumerators.Length)
424 throw new InvalidOperationException(); 424 throw new InvalidOperationException();
425 425
426 return m_generationEnumerators[ m_currentEnumerator ].Current; 426 return m_generationEnumerators[ m_currentEnumerator ].Current;
@@ -461,12 +461,12 @@ namespace OpenSim.Framework
461 /// <filterpriority>2</filterpriority> 461 /// <filterpriority>2</filterpriority>
462 public bool MoveNext() 462 public bool MoveNext()
463 { 463 {
464 if( m_currentEnumerator == -1 ) 464 if (m_currentEnumerator == -1)
465 m_currentEnumerator = 0; 465 m_currentEnumerator = 0;
466 466
467 while( m_currentEnumerator < m_generationEnumerators.Length ) 467 while (m_currentEnumerator < m_generationEnumerators.Length)
468 { 468 {
469 if( m_generationEnumerators[ m_currentEnumerator ].MoveNext() ) 469 if (m_generationEnumerators[ m_currentEnumerator ].MoveNext())
470 return true; 470 return true;
471 471
472 m_currentEnumerator++; 472 m_currentEnumerator++;
@@ -484,7 +484,7 @@ namespace OpenSim.Framework
484 /// <filterpriority>2</filterpriority> 484 /// <filterpriority>2</filterpriority>
485 public void Reset() 485 public void Reset()
486 { 486 {
487 foreach( IEnumerator<KeyValuePair<TKey, TValue>> enumerator in m_generationEnumerators ) 487 foreach (IEnumerator<KeyValuePair<TKey, TValue>> enumerator in m_generationEnumerators)
488 { 488 {
489 enumerator.Reset(); 489 enumerator.Reset();
490 } 490 }
@@ -582,7 +582,7 @@ namespace OpenSim.Framework
582 /// <param name="cache"> 582 /// <param name="cache">
583 /// The cache. 583 /// The cache.
584 /// </param> 584 /// </param>
585 public HashGeneration( CnmMemoryCache<TKey, TValue> cache ) 585 public HashGeneration(CnmMemoryCache<TKey, TValue> cache)
586 { 586 {
587 m_cache = cache; 587 m_cache = cache;
588 m_elements = new Element[m_cache.m_generationElementCount]; 588 m_elements = new Element[m_cache.m_generationElementCount];
@@ -608,16 +608,16 @@ namespace OpenSim.Framework
608 /// <returns> 608 /// <returns>
609 /// Element's index, if found from the generation; -1 otherwise (if element is not found the generation). 609 /// Element's index, if found from the generation; -1 otherwise (if element is not found the generation).
610 /// </returns> 610 /// </returns>
611 private int FindElementIndex( int bucketIndex, TKey key, bool moveToFront, out int previousIndex ) 611 private int FindElementIndex(int bucketIndex, TKey key, bool moveToFront, out int previousIndex)
612 { 612 {
613 previousIndex = -1; 613 previousIndex = -1;
614 int elementIndex = m_buckets[ bucketIndex ]; 614 int elementIndex = m_buckets[ bucketIndex ];
615 while( elementIndex >= 0 ) 615 while (elementIndex >= 0)
616 { 616 {
617 if( m_cache.Comparer.Equals( key, m_elements[ elementIndex ].Key ) ) 617 if (m_cache.Comparer.Equals(key, m_elements[ elementIndex ].Key))
618 { 618 {
619 // Found match 619 // Found match
620 if( moveToFront && previousIndex >= 0 ) 620 if (moveToFront && previousIndex >= 0)
621 { 621 {
622 // Move entry to front 622 // Move entry to front
623 m_elements[ previousIndex ].Next = m_elements[ elementIndex ].Next; 623 m_elements[ previousIndex ].Next = m_elements[ elementIndex ].Next;
@@ -648,9 +648,9 @@ namespace OpenSim.Framework
648 /// <param name="previousIndex"> 648 /// <param name="previousIndex">
649 /// The element's previous index. 649 /// The element's previous index.
650 /// </param> 650 /// </param>
651 private void RemoveElement( int bucketIndex, int entryIndex, int previousIndex ) 651 private void RemoveElement(int bucketIndex, int entryIndex, int previousIndex)
652 { 652 {
653 if( previousIndex >= 0 ) 653 if (previousIndex >= 0)
654 m_elements[ previousIndex ].Next = m_elements[ entryIndex ].Next; 654 m_elements[ previousIndex ].Next = m_elements[ entryIndex ].Next;
655 else 655 else
656 m_buckets[ bucketIndex ] = m_elements[ entryIndex ].Next; 656 m_buckets[ bucketIndex ] = m_elements[ entryIndex ].Next;
@@ -755,7 +755,7 @@ namespace OpenSim.Framework
755 /// <param name="generation"> 755 /// <param name="generation">
756 /// The generation. 756 /// The generation.
757 /// </param> 757 /// </param>
758 public Enumerator( HashGeneration generation ) 758 public Enumerator(HashGeneration generation)
759 { 759 {
760 m_generation = generation; 760 m_generation = generation;
761 m_version = m_generation.m_cache.m_version; 761 m_version = m_generation.m_cache.m_version;
@@ -776,7 +776,7 @@ namespace OpenSim.Framework
776 { 776 {
777 get 777 get
778 { 778 {
779 if( m_currentIndex == 0 || m_currentIndex >= m_generation.Count ) 779 if (m_currentIndex == 0 || m_currentIndex >= m_generation.Count)
780 throw new InvalidOperationException(); 780 throw new InvalidOperationException();
781 781
782 return m_current; 782 return m_current;
@@ -816,19 +816,19 @@ namespace OpenSim.Framework
816 /// </exception> 816 /// </exception>
817 public bool MoveNext() 817 public bool MoveNext()
818 { 818 {
819 if( m_version != m_generation.m_cache.m_version ) 819 if (m_version != m_generation.m_cache.m_version)
820 throw new InvalidOperationException(); 820 throw new InvalidOperationException();
821 821
822 while( m_currentIndex < m_generation.Count ) 822 while (m_currentIndex < m_generation.Count)
823 { 823 {
824 if( m_generation.m_elements[ m_currentIndex ].IsFree ) 824 if (m_generation.m_elements[ m_currentIndex ].IsFree)
825 { 825 {
826 m_currentIndex++; 826 m_currentIndex++;
827 continue; 827 continue;
828 } 828 }
829 829
830 m_current = new KeyValuePair<TKey, TValue>( m_generation.m_elements[ m_currentIndex ].Key, 830 m_current = new KeyValuePair<TKey, TValue>(m_generation.m_elements[ m_currentIndex ].Key,
831 m_generation.m_elements[ m_currentIndex ].Value ); 831 m_generation.m_elements[ m_currentIndex ].Value);
832 m_currentIndex++; 832 m_currentIndex++;
833 return true; 833 return true;
834 } 834 }
@@ -846,7 +846,7 @@ namespace OpenSim.Framework
846 /// <filterpriority>2</filterpriority> 846 /// <filterpriority>2</filterpriority>
847 public void Reset() 847 public void Reset()
848 { 848 {
849 if( m_version != m_generation.m_cache.m_version ) 849 if (m_version != m_generation.m_cache.m_version)
850 throw new InvalidOperationException(); 850 throw new InvalidOperationException();
851 851
852 m_currentIndex = 0; 852 m_currentIndex = 0;
@@ -907,12 +907,12 @@ namespace OpenSim.Framework
907 /// <seealso cref="IGeneration.MakeOld"/> 907 /// <seealso cref="IGeneration.MakeOld"/>
908 public void Clear() 908 public void Clear()
909 { 909 {
910 for( int i = m_buckets.Length - 1 ; i >= 0 ; i-- ) 910 for (int i = m_buckets.Length - 1 ; i >= 0 ; i--)
911 { 911 {
912 m_buckets[ i ] = -1; 912 m_buckets[ i ] = -1;
913 } 913 }
914 914
915 Array.Clear( m_elements, 0, m_elements.Length ); 915 Array.Clear(m_elements, 0, m_elements.Length);
916 Size = 0; 916 Size = 0;
917 m_firstFreeElement = -1; 917 m_firstFreeElement = -1;
918 m_freeCount = 0; 918 m_freeCount = 0;
@@ -934,10 +934,10 @@ namespace OpenSim.Framework
934 /// <see langword="true"/>if the <see cref="IGeneration"/> contains an element with the <see cref="key"/>; 934 /// <see langword="true"/>if the <see cref="IGeneration"/> contains an element with the <see cref="key"/>;
935 /// otherwise <see langword="false"/>. 935 /// otherwise <see langword="false"/>.
936 /// </returns> 936 /// </returns>
937 public bool Contains( int bucketIndex, TKey key ) 937 public bool Contains(int bucketIndex, TKey key)
938 { 938 {
939 int previousIndex; 939 int previousIndex;
940 if( FindElementIndex( bucketIndex, key, true, out previousIndex ) == -1 ) 940 if (FindElementIndex(bucketIndex, key, true, out previousIndex) == -1)
941 return false; 941 return false;
942 942
943 AccessedSinceLastTimeCheck = true; 943 AccessedSinceLastTimeCheck = true;
@@ -953,7 +953,7 @@ namespace OpenSim.Framework
953 /// <filterpriority>1</filterpriority> 953 /// <filterpriority>1</filterpriority>
954 public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator() 954 public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
955 { 955 {
956 return new Enumerator( this ); 956 return new Enumerator(this);
957 } 957 }
958 958
959 /// <summary> 959 /// <summary>
@@ -980,13 +980,13 @@ namespace OpenSim.Framework
980 /// <returns> 980 /// <returns>
981 /// <see langword="true"/>, if remove was successful; otherwise <see langword="false"/>. 981 /// <see langword="true"/>, if remove was successful; otherwise <see langword="false"/>.
982 /// </returns> 982 /// </returns>
983 public bool Remove( int bucketIndex, TKey key ) 983 public bool Remove(int bucketIndex, TKey key)
984 { 984 {
985 int previousIndex; 985 int previousIndex;
986 int entryIndex = FindElementIndex( bucketIndex, key, false, out previousIndex ); 986 int entryIndex = FindElementIndex(bucketIndex, key, false, out previousIndex);
987 if( entryIndex != -1 ) 987 if (entryIndex != -1)
988 { 988 {
989 RemoveElement( bucketIndex, entryIndex, previousIndex ); 989 RemoveElement(bucketIndex, entryIndex, previousIndex);
990 AccessedSinceLastTimeCheck = true; 990 AccessedSinceLastTimeCheck = true;
991 return true; 991 return true;
992 } 992 }
@@ -1020,18 +1020,18 @@ namespace OpenSim.Framework
1020 /// size must fit generation's limits, before element is added to generation. 1020 /// size must fit generation's limits, before element is added to generation.
1021 /// </para> 1021 /// </para>
1022 /// </remarks> 1022 /// </remarks>
1023 public bool Set( int bucketIndex, TKey key, TValue value, long size ) 1023 public bool Set(int bucketIndex, TKey key, TValue value, long size)
1024 { 1024 {
1025 Debug.Assert( m_newGeneration, "It is possible to insert new elements only to newest generation." ); 1025 Debug.Assert(m_newGeneration, "It is possible to insert new elements only to newest generation.");
1026 Debug.Assert( size > 0, "New element size should be more than 0." ); 1026 Debug.Assert(size > 0, "New element size should be more than 0.");
1027 1027
1028 int previousIndex; 1028 int previousIndex;
1029 int elementIndex = FindElementIndex( bucketIndex, key, true, out previousIndex ); 1029 int elementIndex = FindElementIndex(bucketIndex, key, true, out previousIndex);
1030 if( elementIndex == -1 ) 1030 if (elementIndex == -1)
1031 { 1031 {
1032 // New key 1032 // New key
1033 if( Size + size > m_cache.m_generationMaxSize || 1033 if (Size + size > m_cache.m_generationMaxSize ||
1034 (m_nextUnusedElement == m_cache.m_generationElementCount && m_freeCount == 0) ) 1034 (m_nextUnusedElement == m_cache.m_generationElementCount && m_freeCount == 0))
1035 { 1035 {
1036 // Generation is full 1036 // Generation is full
1037 return false; 1037 return false;
@@ -1041,7 +1041,7 @@ namespace OpenSim.Framework
1041 Size += size; 1041 Size += size;
1042 1042
1043 // Get first free entry and update free entry list 1043 // Get first free entry and update free entry list
1044 if( m_firstFreeElement != -1 ) 1044 if (m_firstFreeElement != -1)
1045 { 1045 {
1046 // There was entry that was removed 1046 // There was entry that was removed
1047 elementIndex = m_firstFreeElement; 1047 elementIndex = m_firstFreeElement;
@@ -1055,7 +1055,7 @@ namespace OpenSim.Framework
1055 m_nextUnusedElement++; 1055 m_nextUnusedElement++;
1056 } 1056 }
1057 1057
1058 Debug.Assert( m_elements[ elementIndex ].IsFree, "Allocated element is not free." ); 1058 Debug.Assert(m_elements[ elementIndex ].IsFree, "Allocated element is not free.");
1059 1059
1060 // Move new entry to front 1060 // Move new entry to front
1061 m_elements[ elementIndex ].Next = m_buckets[ bucketIndex ]; 1061 m_elements[ elementIndex ].Next = m_buckets[ bucketIndex ];
@@ -1067,12 +1067,12 @@ namespace OpenSim.Framework
1067 else 1067 else
1068 { 1068 {
1069 // Existing key 1069 // Existing key
1070 if( Size - m_elements[ elementIndex ].Size + size > m_cache.m_generationMaxSize ) 1070 if (Size - m_elements[ elementIndex ].Size + size > m_cache.m_generationMaxSize)
1071 { 1071 {
1072 // Generation is full 1072 // Generation is full
1073 // Remove existing element, because generation is going to be recycled to 1073 // Remove existing element, because generation is going to be recycled to
1074 // old generation and element is stored to new generation 1074 // old generation and element is stored to new generation
1075 RemoveElement( bucketIndex, elementIndex, previousIndex ); 1075 RemoveElement(bucketIndex, elementIndex, previousIndex);
1076 return false; 1076 return false;
1077 } 1077 }
1078 1078
@@ -1113,12 +1113,12 @@ namespace OpenSim.Framework
1113 /// are set to default value (default(TValue) and 0). 1113 /// are set to default value (default(TValue) and 0).
1114 /// </para> 1114 /// </para>
1115 /// </remarks> 1115 /// </remarks>
1116 public bool TryGetValue( int bucketIndex, TKey key, out TValue value, out long size ) 1116 public bool TryGetValue(int bucketIndex, TKey key, out TValue value, out long size)
1117 { 1117 {
1118 // Find entry index, 1118 // Find entry index,
1119 int previousIndex; 1119 int previousIndex;
1120 int elementIndex = FindElementIndex( bucketIndex, key, m_newGeneration, out previousIndex ); 1120 int elementIndex = FindElementIndex(bucketIndex, key, m_newGeneration, out previousIndex);
1121 if( elementIndex == -1 ) 1121 if (elementIndex == -1)
1122 { 1122 {
1123 value = default(TValue); 1123 value = default(TValue);
1124 size = 0; 1124 size = 0;
@@ -1128,10 +1128,10 @@ namespace OpenSim.Framework
1128 value = m_elements[ elementIndex ].Value; 1128 value = m_elements[ elementIndex ].Value;
1129 size = m_elements[ elementIndex ].Size; 1129 size = m_elements[ elementIndex ].Size;
1130 1130
1131 if( !m_newGeneration ) 1131 if (!m_newGeneration)
1132 { 1132 {
1133 // Old generation - remove element, because it is moved to new generation 1133 // Old generation - remove element, because it is moved to new generation
1134 RemoveElement( bucketIndex, elementIndex, previousIndex ); 1134 RemoveElement(bucketIndex, elementIndex, previousIndex);
1135 } 1135 }
1136 1136
1137 AccessedSinceLastTimeCheck = true; 1137 AccessedSinceLastTimeCheck = true;
@@ -1214,7 +1214,7 @@ namespace OpenSim.Framework
1214 /// <see langword="true"/>if the <see cref="IGeneration"/> contains an element with the <see cref="key"/>; 1214 /// <see langword="true"/>if the <see cref="IGeneration"/> contains an element with the <see cref="key"/>;
1215 /// otherwise <see langword="false"/>. 1215 /// otherwise <see langword="false"/>.
1216 /// </returns> 1216 /// </returns>
1217 bool Contains( int bucketIndex, TKey key ); 1217 bool Contains(int bucketIndex, TKey key);
1218 1218
1219 /// <summary> 1219 /// <summary>
1220 /// Make from generation old generation. 1220 /// Make from generation old generation.
@@ -1237,7 +1237,7 @@ namespace OpenSim.Framework
1237 /// <returns> 1237 /// <returns>
1238 /// <see langword="true"/>, if remove was successful; otherwise <see langword="false"/>. 1238 /// <see langword="true"/>, if remove was successful; otherwise <see langword="false"/>.
1239 /// </returns> 1239 /// </returns>
1240 bool Remove( int bucketIndex, TKey key ); 1240 bool Remove(int bucketIndex, TKey key);
1241 1241
1242 /// <summary> 1242 /// <summary>
1243 /// Set or add element to generation. 1243 /// Set or add element to generation.
@@ -1265,7 +1265,7 @@ namespace OpenSim.Framework
1265 /// size must fit generation's limits, before element is added to generation. 1265 /// size must fit generation's limits, before element is added to generation.
1266 /// </para> 1266 /// </para>
1267 /// </remarks> 1267 /// </remarks>
1268 bool Set( int bucketIndex, TKey key, TValue value, long size ); 1268 bool Set(int bucketIndex, TKey key, TValue value, long size);
1269 1269
1270 /// <summary> 1270 /// <summary>
1271 /// Try to get element associated with key. 1271 /// Try to get element associated with key.
@@ -1291,7 +1291,7 @@ namespace OpenSim.Framework
1291 /// are set to default value (default(TValue) and 0). 1291 /// are set to default value (default(TValue) and 0).
1292 /// </para> 1292 /// </para>
1293 /// </remarks> 1293 /// </remarks>
1294 bool TryGetValue( int bucketIndex, TKey key, out TValue value, out long size ); 1294 bool TryGetValue(int bucketIndex, TKey key, out TValue value, out long size);
1295 } 1295 }
1296 1296
1297 #endregion 1297 #endregion
@@ -1357,10 +1357,10 @@ namespace OpenSim.Framework
1357 1357
1358 set 1358 set
1359 { 1359 {
1360 if( value < MinExpirationTime ) 1360 if (value < MinExpirationTime)
1361 value = MinExpirationTime; 1361 value = MinExpirationTime;
1362 1362
1363 if( m_expirationTime == value ) 1363 if (m_expirationTime == value)
1364 return; 1364 return;
1365 1365
1366 m_newGeneration.ExpirationTime = (m_newGeneration.ExpirationTime - m_expirationTime) + value; 1366 m_newGeneration.ExpirationTime = (m_newGeneration.ExpirationTime - m_expirationTime) + value;
@@ -1478,9 +1478,9 @@ namespace OpenSim.Framework
1478 1478
1479 set 1479 set
1480 { 1480 {
1481 if( value < 8 ) 1481 if (value < 8)
1482 value = 8; 1482 value = 8;
1483 if( m_maxCount == value ) 1483 if (m_maxCount == value)
1484 return; 1484 return;
1485 1485
1486 m_maxCount = value; 1486 m_maxCount = value;
@@ -1535,9 +1535,9 @@ namespace OpenSim.Framework
1535 1535
1536 set 1536 set
1537 { 1537 {
1538 if( value < 8 ) 1538 if (value < 8)
1539 value = 8; 1539 value = 8;
1540 if( m_maxSize == value ) 1540 if (m_maxSize == value)
1541 return; 1541 return;
1542 1542
1543 m_maxSize = value; 1543 m_maxSize = value;
@@ -1618,7 +1618,7 @@ namespace OpenSim.Framework
1618 /// <filterpriority>1</filterpriority> 1618 /// <filterpriority>1</filterpriority>
1619 public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator() 1619 public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
1620 { 1620 {
1621 return new Enumerator( this ); 1621 return new Enumerator(this);
1622 } 1622 }
1623 1623
1624 /// <summary> 1624 /// <summary>
@@ -1644,28 +1644,28 @@ namespace OpenSim.Framework
1644 { 1644 {
1645 m_operationsBetweenTimeChecks = DefaultOperationsBetweenTimeChecks; 1645 m_operationsBetweenTimeChecks = DefaultOperationsBetweenTimeChecks;
1646 1646
1647 if( !IsTimeLimited ) 1647 if (!IsTimeLimited)
1648 return; 1648 return;
1649 1649
1650 DateTime now = DateTime.Now; 1650 DateTime now = DateTime.Now;
1651 if( m_newGeneration.AccessedSinceLastTimeCheck ) 1651 if (m_newGeneration.AccessedSinceLastTimeCheck)
1652 { 1652 {
1653 // New generation has been accessed since last check 1653 // New generation has been accessed since last check
1654 // Update it's expiration time. 1654 // Update it's expiration time.
1655 m_newGeneration.ExpirationTime = now + ExpirationTime; 1655 m_newGeneration.ExpirationTime = now + ExpirationTime;
1656 m_newGeneration.AccessedSinceLastTimeCheck = false; 1656 m_newGeneration.AccessedSinceLastTimeCheck = false;
1657 } 1657 }
1658 else if( m_newGeneration.ExpirationTime < now ) 1658 else if (m_newGeneration.ExpirationTime < now)
1659 { 1659 {
1660 // New generation has been expired. 1660 // New generation has been expired.
1661 // --> also old generation must be expired. 1661 // --> also old generation must be expired.
1662 PurgeGeneration( m_newGeneration ); 1662 PurgeGeneration(m_newGeneration);
1663 PurgeGeneration( m_oldGeneration ); 1663 PurgeGeneration(m_oldGeneration);
1664 return; 1664 return;
1665 } 1665 }
1666 1666
1667 if( m_oldGeneration.ExpirationTime < now ) 1667 if (m_oldGeneration.ExpirationTime < now)
1668 PurgeGeneration( m_oldGeneration ); 1668 PurgeGeneration(m_oldGeneration);
1669 } 1669 }
1670 1670
1671 /// <summary> 1671 /// <summary>
@@ -1682,15 +1682,15 @@ namespace OpenSim.Framework
1682 /// <seealso cref="ICnmCache{TKey,TValue}.TryGetValue"/> 1682 /// <seealso cref="ICnmCache{TKey,TValue}.TryGetValue"/>
1683 /// <seealso cref="ICnmCache{TKey,TValue}.Clear"/> 1683 /// <seealso cref="ICnmCache{TKey,TValue}.Clear"/>
1684 /// <seealso cref="ICnmCache{TKey,TValue}.PurgeExpired"/> 1684 /// <seealso cref="ICnmCache{TKey,TValue}.PurgeExpired"/>
1685 public void Remove( TKey key ) 1685 public void Remove(TKey key)
1686 { 1686 {
1687 if( key == null ) 1687 if (key == null)
1688 throw new ArgumentNullException( "key" ); 1688 throw new ArgumentNullException("key");
1689 1689
1690 int bucketIndex = GetBucketIndex( key ); 1690 int bucketIndex = GetBucketIndex(key);
1691 if( !m_newGeneration.Remove( bucketIndex, key ) ) 1691 if (!m_newGeneration.Remove(bucketIndex, key))
1692 { 1692 {
1693 if( !m_oldGeneration.Remove( bucketIndex, key ) ) 1693 if (!m_oldGeneration.Remove(bucketIndex, key))
1694 { 1694 {
1695 CheckExpired(); 1695 CheckExpired();
1696 return; 1696 return;
@@ -1715,19 +1715,19 @@ namespace OpenSim.Framework
1715 /// <seealso cref="ICnmCache{TKey,TValue}.TryGetValue"/> 1715 /// <seealso cref="ICnmCache{TKey,TValue}.TryGetValue"/>
1716 /// <seealso cref="ICnmCache{TKey,TValue}.Clear"/> 1716 /// <seealso cref="ICnmCache{TKey,TValue}.Clear"/>
1717 /// <seealso cref="ICnmCache{TKey,TValue}.PurgeExpired"/> 1717 /// <seealso cref="ICnmCache{TKey,TValue}.PurgeExpired"/>
1718 public void RemoveRange( IEnumerable<TKey> keys ) 1718 public void RemoveRange(IEnumerable<TKey> keys)
1719 { 1719 {
1720 if( keys == null ) 1720 if (keys == null)
1721 throw new ArgumentNullException( "keys" ); 1721 throw new ArgumentNullException("keys");
1722 1722
1723 foreach( TKey key in keys ) 1723 foreach (TKey key in keys)
1724 { 1724 {
1725 if( key == null ) 1725 if (key == null)
1726 continue; 1726 continue;
1727 1727
1728 int bucketIndex = GetBucketIndex( key ); 1728 int bucketIndex = GetBucketIndex(key);
1729 if( !m_newGeneration.Remove( bucketIndex, key ) ) 1729 if (!m_newGeneration.Remove(bucketIndex, key))
1730 m_oldGeneration.Remove( bucketIndex, key ); 1730 m_oldGeneration.Remove(bucketIndex, key);
1731 } 1731 }
1732 1732
1733 CheckExpired(); 1733 CheckExpired();
@@ -1779,27 +1779,27 @@ namespace OpenSim.Framework
1779 /// <seealso cref="ICnmCache{TKey,TValue}.TryGetValue"/> 1779 /// <seealso cref="ICnmCache{TKey,TValue}.TryGetValue"/>
1780 /// <seealso cref="ICnmCache{TKey,TValue}.Clear"/> 1780 /// <seealso cref="ICnmCache{TKey,TValue}.Clear"/>
1781 /// <seealso cref="ICnmCache{TKey,TValue}.PurgeExpired"/> 1781 /// <seealso cref="ICnmCache{TKey,TValue}.PurgeExpired"/>
1782 public bool Set( TKey key, TValue value, long size ) 1782 public bool Set(TKey key, TValue value, long size)
1783 { 1783 {
1784 if( key == null ) 1784 if (key == null)
1785 throw new ArgumentNullException( "key" ); 1785 throw new ArgumentNullException("key");
1786 1786
1787 if( size < 0 ) 1787 if (size < 0)
1788 throw new ArgumentOutOfRangeException( "size", size, "Value's size can't be less than 0." ); 1788 throw new ArgumentOutOfRangeException("size", size, "Value's size can't be less than 0.");
1789 1789
1790 if( size > MaxElementSize ) 1790 if (size > MaxElementSize)
1791 { 1791 {
1792 // Entry size is too big to fit cache - ignore it 1792 // Entry size is too big to fit cache - ignore it
1793 Remove( key ); 1793 Remove(key);
1794 return false; 1794 return false;
1795 } 1795 }
1796 1796
1797 if( size == 0 ) 1797 if (size == 0)
1798 size = 1; 1798 size = 1;
1799 1799
1800 int bucketIndex = GetBucketIndex( key ); 1800 int bucketIndex = GetBucketIndex(key);
1801 m_oldGeneration.Remove( bucketIndex, key ); 1801 m_oldGeneration.Remove(bucketIndex, key);
1802 AddToNewGeneration( bucketIndex, key, value, size ); 1802 AddToNewGeneration(bucketIndex, key, value, size);
1803 CheckExpired(); 1803 CheckExpired();
1804 1804
1805 return true; 1805 return true;
@@ -1828,23 +1828,23 @@ namespace OpenSim.Framework
1828 /// <seealso cref="ICnmCache{TKey,TValue}.RemoveRange"/> 1828 /// <seealso cref="ICnmCache{TKey,TValue}.RemoveRange"/>
1829 /// <seealso cref="ICnmCache{TKey,TValue}.Clear"/> 1829 /// <seealso cref="ICnmCache{TKey,TValue}.Clear"/>
1830 /// <seealso cref="ICnmCache{TKey,TValue}.PurgeExpired"/> 1830 /// <seealso cref="ICnmCache{TKey,TValue}.PurgeExpired"/>
1831 public bool TryGetValue( TKey key, out TValue value ) 1831 public bool TryGetValue(TKey key, out TValue value)
1832 { 1832 {
1833 if( key == null ) 1833 if (key == null)
1834 throw new ArgumentNullException( "key" ); 1834 throw new ArgumentNullException("key");
1835 1835
1836 int bucketIndex = GetBucketIndex( key ); 1836 int bucketIndex = GetBucketIndex(key);
1837 long size; 1837 long size;
1838 if( m_newGeneration.TryGetValue( bucketIndex, key, out value, out size ) ) 1838 if (m_newGeneration.TryGetValue(bucketIndex, key, out value, out size))
1839 { 1839 {
1840 CheckExpired(); 1840 CheckExpired();
1841 return true; 1841 return true;
1842 } 1842 }
1843 1843
1844 if( m_oldGeneration.TryGetValue( bucketIndex, key, out value, out size ) ) 1844 if (m_oldGeneration.TryGetValue(bucketIndex, key, out value, out size))
1845 { 1845 {
1846 // Move element to new generation 1846 // Move element to new generation
1847 AddToNewGeneration( bucketIndex, key, value, size ); 1847 AddToNewGeneration(bucketIndex, key, value, size);
1848 CheckExpired(); 1848 CheckExpired();
1849 return true; 1849 return true;
1850 } 1850 }