Пример #1
0
        public static T HGetOrSet <T>(this LocalCacheService cache, string hashId, string key, Func <T> getValueFunc)
        {
            var val = cache.HGet <T>(hashId, key);

            if (val == null)
            {
                val = getValueFunc();
                cache.HSet(hashId, key, val);
            }
            return(val);
        }
Пример #2
0
        public static T GetOrSet <T>(this LocalCacheService cache, string key, Func <T> getValueFunc, TimeSpan?expiry = null)
        {
            var val = cache.Get <T>(key);

            if (val == null)
            {
                val = getValueFunc();
                cache.Set(key, val, expiry);
            }
            return(val);
        }