Esempio n. 1
0
 /// <summary>
 /// Initializes new instance of this type.
 /// </summary>
 /// <param name="maxSize">Max size of the original cache. Ideally it should be devisible by 3</param>
 /// <param name="keyExtractor">Extracts key value from caching item.</param>
 /// <exception cref="ArgumentOutOfRangeException"><paramref name="maxSize"/> is less than 3.</exception>
 public FastConcurrentLruCache(int maxSize, Converter <TItem, TKey> keyExtractor)
 {
     ArgumentValidator.EnsureArgumentIsGreaterThanOrEqual(maxSize, 3, nameof(maxSize));
     MaxSize      = maxSize;
     KeyExtractor = keyExtractor;
     realCache    = new FastConcurrentLru <TKey, TItem>(maxSize);
 }
Esempio n. 2
0
        public void ConstructAddAndRetrieveWithCustomComparerReturnsValue()
        {
            var lru = new FastConcurrentLru <string, int>(9, 9, StringComparer.OrdinalIgnoreCase);

            lru.GetOrAdd("foo", k => 1);

            lru.TryGet("FOO", out var value).Should().BeTrue();
            value.Should().Be(1);
        }
Esempio n. 3
0
 /// <inheritdoc/>
 public override void Clear() =>
 //TODO: Change to imp.Clear() after updating BitFaster.Caching package to 1.0.4
 realCache = new FastConcurrentLru <TKey, TItem>((int)MaxSize);
Esempio n. 4
0
        public void ConstructAddAndRetrieveWithDefaultCtorReturnsValue()
        {
            var x = new FastConcurrentLru <int, int>(3);

            x.GetOrAdd(1, k => k).Should().Be(1);
        }