Module: Rack::Attack::StoreProxy
- Defined in:
- lib/rack/attack/store_proxy.rb,
lib/rack/attack/store_proxy/dalli_proxy.rb,
lib/rack/attack/store_proxy/mem_cache_proxy.rb,
lib/rack/attack/store_proxy/redis_store_proxy.rb
Defined Under Namespace
Classes: DalliProxy, MemCacheProxy, RedisStoreProxy
Constant Summary collapse
- PROXIES =
[DalliProxy, MemCacheProxy, RedisStoreProxy]
Class Method Summary collapse
Class Method Details
.build(store) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/rack/attack/store_proxy.rb', line 6 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)) || (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. # We also want to use the underlying Dalli client instead of ::ActiveSupport::Cache::MemCacheStore, # and the MemCache client if using Rails 3.x client = store.instance_variable_get(:@data) if (defined?(::Redis::Store) && client.is_a?(Redis::Store)) || (defined?(Dalli::Client) && client.is_a?(Dalli::Client)) || (defined?(MemCache) && client.is_a?(MemCache)) store = store.instance_variable_get(:@data) end end klass = PROXIES.find { |proxy| proxy.handle?(store) } klass ? klass.new(store) : store end |