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); }
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); }
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); }