mirror of
https://github.com/samsonjs/rack-attack.git
synced 2026-04-26 14:57:47 +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,17 +10,19 @@ module Rack
|
||||||
store.class.name == "ActiveSupport::Cache::RedisCacheStore"
|
store.class.name == "ActiveSupport::Cache::RedisCacheStore"
|
||||||
end
|
end
|
||||||
|
|
||||||
def increment(name, amount = 1, **options)
|
if defined?(::ActiveSupport) && ::ActiveSupport::VERSION::MAJOR < 6
|
||||||
# RedisCacheStore#increment ignores options[:expires_in].
|
def increment(name, amount = 1, **options)
|
||||||
#
|
# 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
|
#
|
||||||
# the counter. After that we continue using the original RedisCacheStore#increment.
|
# So in order to workaround this we use RedisCacheStore#write (which sets expiration) to initialize
|
||||||
if options[:expires_in] && !read(name)
|
# the counter. After that we continue using the original RedisCacheStore#increment.
|
||||||
write(name, amount, options)
|
if options[:expires_in] && !read(name)
|
||||||
|
write(name, amount, options)
|
||||||
|
|
||||||
amount
|
amount
|
||||||
else
|
else
|
||||||
super
|
super
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue