Better cache interface

This commit is contained in:
Aaron Suggs 2012-08-06 14:16:08 -04:00
parent e135f17386
commit 6784f21612
2 changed files with 6 additions and 3 deletions

View file

@ -7,7 +7,7 @@ module Rack::Attack
class << self class << self
attr_accessor :cache, :notifier, :blacklisted_response, :throttled_response attr_accessor :notifier, :blacklisted_response, :throttled_response
def whitelist(name, &block) def whitelist(name, &block)
self.whitelists[name] = Whitelist.new(name, block) self.whitelists[name] = Whitelist.new(name, block)
@ -29,7 +29,6 @@ module Rack::Attack
@app = app @app = app
# Set defaults # Set defaults
@cache ||= Cache.new
@notifier ||= ActiveSupport::Notifications if defined?(ActiveSupport::Notifications) @notifier ||= ActiveSupport::Notifications if defined?(ActiveSupport::Notifications)
@blacklisted_response ||= lambda {|env| [503, {}, ['Blocked']] } @blacklisted_response ||= lambda {|env| [503, {}, ['Blocked']] }
@throttled_response ||= lambda {|env| @throttled_response ||= lambda {|env|
@ -78,6 +77,10 @@ module Rack::Attack
notifier.instrument('rack.attack', req) if notifier notifier.instrument('rack.attack', req) if notifier
end end
def cache
@cache ||= Cache.new
end
def clear! def clear!
@whitelists, @blacklists, @throttles = {}, {}, {} @whitelists, @blacklists, @throttles = {}, {}, {}
end end

View file

@ -1,5 +1,5 @@
module Rack module Rack
module Attack module Attack
VERSION = '1.1.0' VERSION = '1.2.0'
end end
end end