Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 3
0
        public async Task <T> GetWithDefaultValueAsync <T>(string key, Func <Task <T> > defaultValueFuncAsync, CacheEntryOptions options)
        {
            T result = this.Get <T>(key);

            if (result == null)
            {
                T defaultValue = await defaultValueFuncAsync();

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

            return(result);
        }