mirror of
https://github.com/samsonjs/rack-attack.git
synced 2026-04-27 15:07:41 +00:00
Avoid RedisCacheStore#increment on Rails 6+ (#597)
Rails has handled increment+expires_in since
6.0 (9d5b02ec50),
and more recent versions add pipeline optimizations on top of that.
This commit is contained in:
parent
27ada96682
commit
d9fedfae4f
1 changed files with 12 additions and 10 deletions
|
|
@ -10,8 +10,9 @@ module Rack
|
||||||
store.class.name == "ActiveSupport::Cache::RedisCacheStore"
|
store.class.name == "ActiveSupport::Cache::RedisCacheStore"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if defined?(::ActiveSupport) && ::ActiveSupport::VERSION::MAJOR < 6
|
||||||
def increment(name, amount = 1, **options)
|
def increment(name, amount = 1, **options)
|
||||||
# RedisCacheStore#increment ignores options[:expires_in].
|
# RedisCacheStore#increment ignores options[:expires_in] in versions prior to 6.
|
||||||
#
|
#
|
||||||
# So in order to workaround this we use RedisCacheStore#write (which sets expiration) to initialize
|
# So in order to workaround this we use RedisCacheStore#write (which sets expiration) to initialize
|
||||||
# the counter. After that we continue using the original RedisCacheStore#increment.
|
# the counter. After that we continue using the original RedisCacheStore#increment.
|
||||||
|
|
@ -23,6 +24,7 @@ module Rack
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def read(name, options = {})
|
def read(name, options = {})
|
||||||
super(name, options.merge!(raw: true))
|
super(name, options.merge!(raw: true))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue