コード例 #1
0
        public void should_respect_no_expiry()
        {
            var cache = new PrefetchedCache<string, int>(OnFetchFunc);
            cache.Get("a");
            cache.Get("a");
            cache.Get("a");

            _fetchCount.Should().Be(1);
        }
コード例 #2
0
        public void should_respect_long_expiry()
        {
            var cache = new PrefetchedCache<string, int>(OnFetchFunc, TimeSpan.FromHours(1));
            cache.Get("a");
            cache.Get("a");
            cache.Get("a");

            _fetchCount.Should().Be(1);
        }
コード例 #3
0
 public void should_allow_manual_refresh_with_no_expiry()
 {
     var cache = new PrefetchedCache<string, int>(OnFetchFunc);
     cache.Get("a");
     cache.Get("a");
     cache.Get("a");
     _fetchCount.Should().Be(1);
     cache.Refresh();
     _fetchCount.Should().Be(2);
 }
コード例 #4
0
        public void should_repopulate_cache_on_expiry()
        {
            var cache = new PrefetchedCache<string, int>(OnFetchFunc, TimeSpan.FromSeconds(1));
            cache.Count.Should().Be(2);

            Thread.Sleep(1000);

            cache.Get("a");
            cache.Get("a");
            cache.Get("a");

            _fetchCount.Should().Be(2);
        }