Exemple #1
0
        public static T Get <T>(this RedisCache cache, string key)
        {
            var data = cache.Get(key);

            using (var stream = new MemoryStream(data))
            {
                return(Serializer.Deserialize <T>(stream));
            }
        }
Exemple #2
0
 public static T Put <T>(this RedisCache cache, string cacheKey, Func <T> sourceGetter, DateTime absoluteExpiration) where T : class
 {
     return(Get(
                (out T cacheData) =>
     {
         cacheData = cache.Get <T>(cacheKey);
         return cacheData != null;
     },
                sourceGetter,
                cacheData => cache.Set(cacheKey, cacheData, absoluteExpiration)));
 }
        private void SetCache()
        {
            var cache = new RedisCache(_redisCacheOptions);

            var key = "CacheKey";
            var value = Encoding.UTF8.GetBytes($"Hello From Redis Caching {DateTime.Now.ToLongTimeString()}");
            cache.Set(key, value, new DistributedCacheEntryOptions());

            var fromCache = Encoding.UTF8.GetString(cache.Get(key));

            ViewData["FromCache"] = fromCache;
        }