Esempio n. 1
0
        protected static async Task RedisCache_Absolute_Expire_Async(RedisCacheProvider redisCache)
        {
            Console.WriteLine("Async test absolute expire start...");
            Console.Write(Environment.NewLine);

            var key     = Guid.NewGuid().ToString("N");
            var value   = "something";
            var options = CacheEntryOptionsFactory.AbSolute().Timeout(TimeSpan.FromMilliseconds(300));

            await redisCache.SetAsync(key, value, options).ConfigureAwait(false);

            Console.WriteLine(string.Format("Async set key:{0} with value:{1} by expire:{2}",
                                            key, value, options.ExpirationTimeout.TotalMilliseconds));

            Console.WriteLine(string.Format("Async get key:{0} with value:{1}", key, await redisCache.GetAsync <string>(key).ConfigureAwait(false)));

            Thread.Sleep(350);
            Console.WriteLine(string.Format("After expire:{0} async get key:{1} with value:{2}",
                                            options.ExpirationTimeout.TotalMilliseconds, key, await redisCache.GetAsync <string>(key).ConfigureAwait(false)));

            Console.Write(Environment.NewLine);
            Console.WriteLine("Async test absolute expire end...");
        }