コード例 #1
0
        public async Task Expired_item_returns_correct_GetTimeToLive()
        {
            var key = "int:key";

            var value = await Cache.GetOrCreateAsync(key, TimeSpan.FromMilliseconds(2000), () => Task.FromResult(1));

            var ttl = await Cache.GetTimeToLiveAsync(key);

            Assert.That(value, Is.EqualTo(1));
            Assert.That(ttl.Value.TotalMilliseconds, Is.GreaterThan(0));

            await Cache.RemoveAsync(key);

            value = await Cache.GetAsync <int>(key);

            ttl = await Cache.GetTimeToLiveAsync(key);

            Assert.That(value, Is.EqualTo(0));
            Assert.That(ttl, Is.Null);
        }
コード例 #2
0
        public async Task Expired_item_returns_correct_GetTimeToLive()
        {
            var ormliteCache = Cache as OrmLiteCacheClient;
            var key          = "int:key";

            var value = await Cache.GetOrCreateAsync(key, TimeSpan.FromMilliseconds(2000), () => Task.FromResult(1));

            var ttl = await Cache.GetTimeToLiveAsync(key);

            if (ormliteCache != null)
            {
                using var db = ormliteCache.DbFactory.OpenDbConnection();
                var row = await db.SingleByIdAsync <CacheEntry>(key);

                Assert.That(row, Is.Not.Null);
                Assert.That(row.ExpiryDate, Is.Not.Null);
            }

            Assert.That(value, Is.EqualTo(1));
            Assert.That(ttl.Value.TotalMilliseconds, Is.GreaterThan(0));

            await Cache.RemoveAsync(key);

            value = await Cache.GetAsync <int>(key);

            ttl = await Cache.GetTimeToLiveAsync(key);

            Assert.That(value, Is.EqualTo(0));
            Assert.That(ttl, Is.Null);

            if (ormliteCache != null)
            {
                using var db = ormliteCache.DbFactory.OpenDbConnection();
                var row = db.SingleById <CacheEntry>(key);
                Assert.That(row, Is.Null);
            }
        }