mirror of
https://github.com/samsonjs/rack-attack.git
synced 2026-03-25 09:25:49 +00:00
Support a Dalli Connection Pool
This commit is contained in:
parent
d76444164a
commit
128c5aa9bf
3 changed files with 17 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
]
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue