コード例 #1
0
        /// <summary>
        /// 保存api调用记录
        /// </summary>
        /// <returns></returns>
        private async Task SaveAsync(HttpContext context)
        {
            //循环保存记录
            foreach (RateValve valve in _options.Global.Valves.Where(x => x is RateValve))
            {
                //取得识别值
                var policyValue = context.GetPolicyValue(_options, valve.Policy, valve.PolicyKey);

                //保存记录
                await _cache.AddApiRecordAsync(Common.GlobalApiKey, valve.Policy, valve.PolicyKey, policyValue, nowTime, valve.Duration);
            }
        }
コード例 #2
0
        /// <summary>
        /// 保存api调用记录
        /// </summary>
        /// <returns></returns>
        private async Task SaveAsync(FilterContext context)
        {
            DateTime nowTime = DateTime.Now;

            //循环保存记录
            foreach (RateValve valve in _valves.Where(x => x is RateValve))
            {
                //取得识别值
                var policyValue = context.HttpContext.GetPolicyValue(_options, valve.Policy, valve.PolicyKey);

                //保存记录
                await _cache.AddApiRecordAsync(_api, valve.Policy, valve.PolicyKey, policyValue, nowTime, valve.Duration);
            }
        }