Exemplo n.º 1
0
        public void ReturnsTrueWhenHasCache()
        {
            var cache = new LazyResetCache <string>(new TimeSpan(1, 0, 0));

            cache.Init(() => "piyo");
            Assert.True(cache.Exists(), "should have something");
        }
Exemplo n.º 2
0
        public void ReturnsCachedValue()
        {
            var cache = new LazyResetCache <string>(new TimeSpan(1, 0, 0));

            cache.Init(() => "piyo");
            Assert.Equal("piyo", cache.Get());
        }
Exemplo n.º 3
0
        public async void Expires()
        {
            var cache = new LazyResetCache <int>((new TimeSpan(0, 0, 0, 0, 100)));
            var i     = 0;

            cache.Init(() =>
            {
                Task.Delay(100).Wait();
                return(i);
            });
            Assert.Equal(0, cache.Get());

            await Task.Delay(200);

            i++;
            Assert.Equal(0, cache.Get());
            await Task.Delay(200);

            Assert.Equal(1, cache.Get());
        }
Exemplo n.º 4
0
        public IActionResult Index()
        {
            var cached = cache.Exists();

            if (!cached)
            {
                cache.Init(() =>
                {
                    Console.WriteLine("Start Set(): " + DateTime.Now.ToString());
                    Task.Delay(1000).Wait();
                    var time = DateTime.Now.ToString();
                    Console.WriteLine("Complete Set()." + time);
                    return(time);
                });
            }

            ViewData["Requested"] = DateTime.Now.ToString();
            ViewData["Cached"]    = cache.Get();
            ViewData["IsCached"]  = cached;

            return(View());
        }
        public void Success()
        {
            var cache = new LazyResetCache <string>(new TimeSpan(1, 0, 0));

            cache.Init(() => "hoge");
        }