Пример #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");
        }
Пример #2
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());
        }
Пример #3
0
        public void ReturnsFalseFirst()
        {
            var cache = new LazyResetCache <string>(new TimeSpan(1, 0, 0));

            Assert.False(cache.Exists(), "should be null");
        }