diff --git a/lib/rack/attack/store_proxy.rb b/lib/rack/attack/store_proxy.rb index abd9089..ac7dda9 100644 --- a/lib/rack/attack/store_proxy.rb +++ b/lib/rack/attack/store_proxy.rb @@ -14,8 +14,14 @@ module Rack if defined?(::Redis::Store) && store.is_a?(::Redis::Store) RedisStoreProxy.new(store) - elsif defined?(::Dalli) && store.is_a?(::Dalli::Client) - DalliProxy.new(store) + elsif store.respond_to?(:with) + store.with do |conn| + if defined?(::Dalli) && conn.is_a?(::Dalli::Client) + DalliProxy.new(store) + else + raise NotImplementedError + end + end else store end @@ -81,6 +87,12 @@ module Rack rescue Dalli::DalliError end + def delete(key) + with do |client| + client.delete(key) + end + rescue Dalli::DalliError + end end end end diff --git a/rack-attack.gemspec b/rack-attack.gemspec index 4bde2f2..aafb1ba 100644 --- a/rack-attack.gemspec +++ b/rack-attack.gemspec @@ -29,5 +29,5 @@ Gem::Specification.new do |s| s.add_development_dependency 'activesupport', '>= 3.0.0' s.add_development_dependency 'redis-activesupport' s.add_development_dependency 'dalli' + s.add_development_dependency 'connection_pool' end - diff --git a/spec/integration/rack_attack_cache_spec.rb b/spec/integration/rack_attack_cache_spec.rb index adc755a..5ea2201 100644 --- a/spec/integration/rack_attack_cache_spec.rb +++ b/spec/integration/rack_attack_cache_spec.rb @@ -15,11 +15,13 @@ describe Rack::Attack::Cache do require 'active_support/cache/dalli_store' require 'active_support/cache/redis_store' + require 'connection_pool' cache_stores = [ ActiveSupport::Cache::MemoryStore.new, ActiveSupport::Cache::DalliStore.new("localhost"), ActiveSupport::Cache::RedisStore.new("localhost"), Dalli::Client.new, + ConnectionPool.new { Dalli::Client.new }, Redis::Store.new ]