From 6784f216128074d777715e1ed7e5b0964cea2cd6 Mon Sep 17 00:00:00 2001 From: Aaron Suggs Date: Mon, 6 Aug 2012 14:16:08 -0400 Subject: [PATCH] Better cache interface --- lib/rack/attack.rb | 7 +++++-- lib/rack/attack/version.rb | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/rack/attack.rb b/lib/rack/attack.rb index 3c90002..4511e99 100644 --- a/lib/rack/attack.rb +++ b/lib/rack/attack.rb @@ -7,7 +7,7 @@ module Rack::Attack class << self - attr_accessor :cache, :notifier, :blacklisted_response, :throttled_response + attr_accessor :notifier, :blacklisted_response, :throttled_response def whitelist(name, &block) self.whitelists[name] = Whitelist.new(name, block) @@ -29,7 +29,6 @@ module Rack::Attack @app = app # Set defaults - @cache ||= Cache.new @notifier ||= ActiveSupport::Notifications if defined?(ActiveSupport::Notifications) @blacklisted_response ||= lambda {|env| [503, {}, ['Blocked']] } @throttled_response ||= lambda {|env| @@ -78,6 +77,10 @@ module Rack::Attack notifier.instrument('rack.attack', req) if notifier end + def cache + @cache ||= Cache.new + end + def clear! @whitelists, @blacklists, @throttles = {}, {}, {} end diff --git a/lib/rack/attack/version.rb b/lib/rack/attack/version.rb index 6d2484b..0709ab6 100644 --- a/lib/rack/attack/version.rb +++ b/lib/rack/attack/version.rb @@ -1,5 +1,5 @@ module Rack module Attack - VERSION = '1.1.0' + VERSION = '1.2.0' end end