コード例 #1
0
        public void ManualExpiration(bool compressValues, bool useBasic)
        {
            TimeSpan            cacheLifeTime = TimeSpan.FromMinutes(5);
            RedisCachingService service       = RedisHelpers.GetRedis(compressValues: compressValues, useBasic: useBasic);

            service.Clear();
            Foobar cachable = RedisHelpers.GetCachableObject();

            string   cachableKey    = RedisHelpers.CachableKey;
            DateTime startedCaching = DateTime.UtcNow;

            service.Cache(cachableKey, cachable);
            DateTime endedCaching = DateTime.UtcNow;
            ICachedObject <Foobar> existsRetrievedWrapper = service.Retrieve <Foobar>(cachableKey);

            service.Invalidate(cachableKey);
            ICachedObject <Foobar> retrievedWrapper = service.Retrieve <Foobar>(cachableKey);

            Assert.Empty(service);
            Assert.NotNull(existsRetrievedWrapper);
            Assert.Null(retrievedWrapper);
        }