/// <summary> /// 创建一个设置缓存值的任务 /// </summary> /// <typeparam name="T">缓存值类型</typeparam> /// <param name="cacheKey">缓存键</param> /// <param name="cacheFactory">创建缓存值和策略的工厂方法</param> /// <returns>一个创建和设置缓存值的任务</returns> private async Task <T> SetValue <T>(string cacheKey, Func <Task <CacheEntry <T> > > cacheFactory) { await Task.Yield(); var cacheEntry = await cacheFactory(); cacheEntry.Validate(); var policy = cacheEntry.CachePolicyItem; var value = cacheEntry.Value; if (policy.CacheState == CacheState.Valid) { await _cacheProvider.Set(cacheKey, value, policy); } return(value); }