/// <summary>
        /// This method is called periodically to refresh the thottle policy.
        /// </summary>
        /// <remarks>
        /// Currently, this method does no updates to the policy. However, in the future, we'll update the throttle policy dynamically. These will require
        /// making async calls to Table Storage.
        /// </remarks>
        /// <returns>a task</returns>
        public Task <IPolicyRepository> RefreshingThottlePolicy()
        {
            // get policy object from cache
            var policy = this.PolicyRepository.FirstOrDefault(ThrottleManager.GetPolicyKey());

            // here where we will update the policy

            // apply policy updates
            ThrottleManager.UpdatePolicy(policy, this.PolicyRepository);

            return(Task.FromResult(this.PolicyRepository));
        }
Beispiel #2
0
        public void UpdateRateLimits()
        {
            //init policy repo
            var policyRepository = new PolicyCacheRepository();

            //get policy object from cache
            var policy = policyRepository.FirstOrDefault(ThrottleManager.GetPolicyKey());

            //update client rate limits
            policy.ClientRules["api-client-key-1"] =
                new RateLimits {
                PerMinute = 50, PerHour = 500
            };

            //add new client rate limits
            policy.ClientRules.Add("api-client-key-3",
                                   new RateLimits {
                PerMinute = 60, PerHour = 600
            });

            //apply policy updates
            ThrottleManager.UpdatePolicy(policy, policyRepository);
        }