/// <summary> /// 获取指定键的缓存项,不存在则从指定委托获取,并回存到缓存中再返回 /// </summary> public static TResult Get <TResult>(this IDistributedCache cache, string key, Func <TResult> getFunc, int cacheSeconds) { Check.GreaterThan(cacheSeconds, nameof(cacheSeconds), 0); DistributedCacheEntryOptions options = new DistributedCacheEntryOptions(); options.SetAbsoluteExpiration(TimeSpan.FromSeconds(cacheSeconds)); return(cache.GetCache <TResult>(key, getFunc, options)); }
/// <summary> /// Syncronous version of GetCacheGroupAsync /// </summary> /// <typeparam name="T"></typeparam> /// <param name="cache"></param> /// <param name="group"></param> /// <returns></returns> public static T[] GetCacheGroup <T>(this IDistributedCache cache, string group) { string[] keyList = GetKeys(group); T[] result = new T[keyList.Length]; for (int i = 0; i < result.Length; ++i) { result[i] = cache.GetCache <T>(keyList[i]); } return(result); }