Class: RateLimiter::BucketStore
- Inherits:
-
Object
- Object
- RateLimiter::BucketStore
- Defined in:
- lib/fluent/plugin/rate_limiter.rb
Overview
BucketStore class, organizes the all the group buckets Attributes:
+buckets+: Hash containing all the group buckets
Instance Method Summary collapse
-
#clean_buckets ⇒ Object
Cleans the buckets that have expired.
-
#get_bucket(group, quota) ⇒ Object
Gets the bucket for the group Arguments:
group
: Group for which the bucket is requiredquota
: Quota object containing the bucket size and duration. -
#initialize ⇒ BucketStore
constructor
A new instance of BucketStore.
Constructor Details
#initialize ⇒ BucketStore
Returns a new instance of BucketStore.
98 99 100 |
# File 'lib/fluent/plugin/rate_limiter.rb', line 98 def initialize @buckets = {} end |
Instance Method Details
#clean_buckets ⇒ Object
Cleans the buckets that have expired
111 112 113 114 115 116 |
# File 'lib/fluent/plugin/rate_limiter.rb', line 111 def clean_buckets lru_group, lru_bucket = @buckets.first if !lru_group.nil? && lru_bucket.expired @buckets.delete(lru_group) end end |
#get_bucket(group, quota) ⇒ Object
Gets the bucket for the group Arguments:
+group+: Group for which the bucket is required
+quota+: Quota object containing the bucket size and duration
106 107 108 |
# File 'lib/fluent/plugin/rate_limiter.rb', line 106 def get_bucket(group, quota) @buckets[[group, quota.name]] = @buckets.delete([group, quota.name]) || Bucket.new( group, quota.bucket_size, quota.duration) end |