Пример #1
0
        public T GetWithDefaultValue <T>(string key, Func <T> defaultValueFunc, CacheEntryOptions options)
        {
            T result = this.Get <T>(key);

            if (result == null)
            {
                T defaultValue = defaultValueFunc();

                this.Set(key, defaultValue, options);
                return(defaultValue);
            }

            return(result);
        }
Пример #2
0
        public void Set <T>(string key, T value, CacheEntryOptions options)
        {
            if (options == null)
            {
                this.memoryCache.Set(key, value);
            }

            else
            {
                this.memoryCache.Set(
                    key,
                    value,
                    new MemoryCacheEntryOptions()
                {
                    AbsoluteExpiration = options.AbsoluteExpiration,
                    SlidingExpiration  = options.SlidingExpiration,
                    Priority           = (CacheItemPriority)options.Priority
                }
                    );
            }

            this.keys.Add(key);
        }