mirror of
https://github.com/samsonjs/rack-attack.git
synced 2026-03-25 09:25:49 +00:00
feature: support for ActiveSupport::MemCacheStore
This commit is contained in:
parent
6789b28c7b
commit
397a7ce7b4
3 changed files with 6 additions and 3 deletions
|
|
@ -6,14 +6,14 @@ module Rack
|
|||
def self.build(store)
|
||||
# RedisStore#increment needs different behavior, so detect that
|
||||
# (method has an arity of 2; must call #expire separately
|
||||
if defined?(::ActiveSupport::Cache::RedisStore) && store.is_a?(::ActiveSupport::Cache::RedisStore)
|
||||
if (defined?(::ActiveSupport::Cache::RedisStore) && store.is_a?(::ActiveSupport::Cache::RedisStore)) ||
|
||||
(defined?(::ActiveSupport::Cache::MemCacheStore) && store.is_a?(::ActiveSupport::Cache::MemCacheStore))
|
||||
# ActiveSupport::Cache::RedisStore doesn't expose any way to set an expiry,
|
||||
# so use the raw Redis::Store instead
|
||||
store = store.instance_variable_get(:@data)
|
||||
end
|
||||
|
||||
klass = PROXIES.find { |proxy| proxy.handle?(store) }
|
||||
|
||||
klass ? klass.new(store) : store
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ module Rack
|
|||
if defined?(::ConnectionPool) && store.is_a?(::ConnectionPool)
|
||||
store.with { |conn| conn.is_a?(::Dalli::Client) }
|
||||
else
|
||||
store.is_a?(::Dalli::Client)
|
||||
store.is_a?(::Dalli::Client) || store.is_a?(::ActiveSupport::Cache::MemCacheStore)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -17,12 +17,14 @@ describe Rack::Attack::Cache do
|
|||
end
|
||||
|
||||
require 'active_support/cache/dalli_store'
|
||||
require 'active_support/cache/mem_cache_store'
|
||||
require 'active_support/cache/redis_store'
|
||||
require 'connection_pool'
|
||||
cache_stores = [
|
||||
ActiveSupport::Cache::MemoryStore.new,
|
||||
ActiveSupport::Cache::DalliStore.new("127.0.0.1"),
|
||||
ActiveSupport::Cache::RedisStore.new("127.0.0.1"),
|
||||
ActiveSupport::Cache::MemCacheStore.new("127.0.0.1"),
|
||||
Dalli::Client.new,
|
||||
ConnectionPool.new { Dalli::Client.new },
|
||||
Redis::Store.new
|
||||
|
|
@ -54,6 +56,7 @@ describe Rack::Attack::Cache do
|
|||
@cache.send(:do_count, @key, @expires_in).must_equal 2
|
||||
end
|
||||
end
|
||||
|
||||
describe "do_count after expires_in" do
|
||||
it "must be 1" do
|
||||
@cache.send(:do_count, @key, @expires_in)
|
||||
|
|
|
|||
Loading…
Reference in a new issue