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:
Jonathan del Strother 2023-11-20 16:59:08 +00:00 committed by GitHub
parent 27ada96682
commit d9fedfae4f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -10,8 +10,9 @@ module Rack
store.class.name == "ActiveSupport::Cache::RedisCacheStore"
end
if defined?(::ActiveSupport) && ::ActiveSupport::VERSION::MAJOR < 6
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
# the counter. After that we continue using the original RedisCacheStore#increment.
@ -23,6 +24,7 @@ module Rack
super
end
end
end
def read(name, options = {})
super(name, options.merge!(raw: true))