コード例 #1
0
 public static void can_read_item_from_underlying_cache(Test t)
 {
     foreach (var key in new[] { 1, 2 })
     {
         var cache = new ReadThroughCache <int, int>(new ValueIsKey <int, int>(), 3, null);
         t.Assert(key, cache[key]);
     }
 }
コード例 #2
0
        public static void get_reads_though(Test t)
        {
            var source = new HerdValueIsKey <int, int>();
            var thp    = source.WithThunderingHerdProtection();
            var c      = new ReadThroughCache <int, int>(thp, 10, null);

            t.Assert(1, c[1]);
        }
コード例 #3
0
        public static void invalidate_removes_item_from_gen0(Test t)
        {
            var cache = new ReadThroughCache <int, int>(new ValueIsKey <int, int>(), 10, null);

            t.Assert(1, cache[1]);
            t.Assert(1, cache.Count);
            cache.Remove(1);
            t.Assert(0, cache.Count);
        }
コード例 #4
0
        public static void eviction_raises_event_with_evicted_items(Test t)
        {
            var cache = new ReadThroughCache <int, int>(new ValueIsKey <int, int>(), 10, null);
            IReadOnlyDictionary <int, int> evicted = null;

            t.Assert(1, cache[1]);
            cache.Evicted += (sender, key) => evicted = key;
            cache.Clear();
            t.Assert(1, evicted.Count);
            t.Assert(0, cache.Count);
        }
コード例 #5
0
        public static void drops_items_in_gen1_when_gen0_is_full(Test t)
        {
            var cache = new ReadThroughCache <int, int>(new ValueIsKey <int, int>(), 3, null);

            for (int i = 1; i <= 7; i++)
            {
                t.Assert(i, cache[i]);
            }
            t.Assert(3, cache._gen1.Count);
            t.Assert(1, cache._gen0.Count);
        }
コード例 #6
0
        public static async Task can_read_item_from_underlying_cache(Test t)
        {
            foreach (var key in new[] { 1, 2 })
            {
                var cache  = new ReadThroughCache <int, int>(new ValueIsKey <int, int>(), 3, null);
                var actual = await cache.GetAsync(key);

                if (actual != key)
                {
                    t.Error($"Expected {key} but got {actual}");
                }
            }
        }
コード例 #7
0
        public static async Task drops_items_in_gen1_when_gen0_is_full(Test t)
        {
            var cache = new ReadThroughCache <int, int>(new ValueIsKey <int, int>(), 3, null);

            for (int i = 1; i <= 7; i++)
            {
                var actual = await cache.GetAsync(i);

                if (actual != i)
                {
                    t.Error($"Expected {i} but got {actual}");
                }
            }
            t.Assert(3, cache._gen1.Count);
            t.Assert(1, cache._gen0.Count);
        }