lib/rack/throttle/limiters/sliding_window.rb in improved-rack-throttle-0.8.0 vs lib/rack/throttle/limiters/sliding_window.rb in improved-rack-throttle-0.9.0
- old
+ new
@@ -24,17 +24,17 @@
# @param [Rack::Request] request
# @return [Boolean]
def allowed?(request)
t1 = request_start_time(request)
key = cache_key(request)
- bucket = cache_get(key) rescue nil
+ bucket = Marshal.load(cache_get(key)) rescue nil
bucket ||= LeakyBucket.new(options[:burst], options[:average])
bucket.maximum, bucket.outflow = options[:burst], options[:average]
bucket.leak!
bucket.increment!
allowed = !bucket.full?
begin
- cache_set(key, bucket)
+ cache_set(key, Marshal.dump(bucket))
allowed
rescue StandardError => e
allowed = true
# If an error occurred while trying to update the timestamp stored
# in the cache, we will fall back to allowing the request through.