Exemple #1
0
        private static async Task <int> FetchNumOfAppliesOnPeriod(int period, bool resetCache)
        {
            using (var client = CacheHelper.CreateCacheClient(DefaultClientName))
            {
                var key = ZeroActivityPeriodKey + "/" + period;

                if (resetCache)
                {
                    var val = await DalZeroActivity.FetchNumOfApplicationsAsync(period);

                    var setResult = await client.SetAsync(key, val, TimeSpan.FromMinutes(30));

                    if (!setResult.Success)
                    {
                        Logger.Error($"设置redis缓存({key})失败;Error:{setResult.Message}", setResult.Exception);
                    }
                    return(setResult.Value);
                }
                else
                {
                    var getResult = await client.GetOrSetAsync(key,
                                                               async() => await DalZeroActivity.FetchNumOfApplicationsAsync(period),
                                                               TimeSpan.FromMinutes(30));

                    if (!getResult.Success)
                    {
                        Logger.Error($"获取redis缓存({key})失败;Error:{getResult.Message}", getResult.Exception);
                    }
                    return(getResult.Value);
                }
            }
        }
Exemple #2
0
        private static async Task <int> FetchNumOfAppliesOnPeriod(int period)
        {
            using (var client = CacheHelper.CreateCacheClient(DefaultClientName))
            {
                var numOfAppliesResult = await client.GetOrSetAsync(GlobalConstant.NumOfApplications + period + "/", () => DalZeroActivity.FetchNumOfApplicationsAsync(period), GlobalConstant.NumOfApplicationsExpiration);

                if (numOfAppliesResult.Success)
                {
                    return(numOfAppliesResult.Value);
                }
                else
                {
                    Logger.Warn($"缓存redis失败NumOfApplications:{GlobalConstant.NumOfApplications + period + "/"};Error:{numOfAppliesResult.Message}", numOfAppliesResult.Exception);
                    return(await DalZeroActivity.FetchNumOfApplicationsAsync(period));
                }
            }
        }