Пример #1
0
        public static void Test()
        {
            var func = Memoizer.Memoize <int, int>(a => a, b => b
                                                   .Capacity(1)
                                                   .Expiration(TimeSpan.FromSeconds(1))
                                                   .LocalThread()
                                                   );

            Memoizer.LocalThreadMemoizeOne <int, int>(a => a, TimeSpan.FromSeconds(1));
        }
Пример #2
0
        public void Memoize()
        {
            int i = 1;
            var a = new object();
            var b = new object();

            var func = Memoizer.Memoize((object o) => i++);

            func(a).AssertEqual(1);
            func(b).AssertEqual(2);
            func(a).AssertEqual(1);
            func(b).AssertEqual(2);

            func(null).AssertEqual(3);
            func(null).AssertEqual(3);
        }
Пример #3
0
        public void MemoizeCapacity()
        {
            int i = 1;
            var a = new object();
            var b = new object();
            var c = new object();

            var func = Memoizer.Memoize((object o) => i++, v => v.Capacity(2));

            func(a).AssertEqual(1);
            func(a).AssertEqual(1);
            func(b).AssertEqual(2);
            func(b).AssertEqual(2);
            func(a).AssertEqual(1);
            func(c).AssertEqual(3);
            func(a).AssertEqual(4);
        }