Skip to content

Commit

Permalink
Set explicit string key for Rails cache (#123)
Browse files Browse the repository at this point in the history
Thanks to rails/rails#50008,
I found that the Rails cache key should be treated as String.
This patch changes the Rails cache to set String instead of Integer
to follow the expected cache key type.
  • Loading branch information
yykamei authored Nov 12, 2023
1 parent 29cf9f5 commit b5e2b4c
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion test/dummy/app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def welcome_email

def cache
user = User.find(params.require(:user_id))
result = Rails.cache.fetch(user.id, expires_in: 1.minutes) do
result = Rails.cache.fetch("key_#{user.id}", expires_in: 1.minutes) do
user.slow_method
end
logger.info(result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class CacheGenerateTest < ActionDispatch::IntegrationTest
test 'returns key' do
get "/users/#{@user.id}/cache"

assert_equal @user.id, @event.key
assert_equal "key_#{@user.id}", @event.key
end

if Gem::Version.new(Rails.version) >= Gem::Version.new('6.1')
Expand Down
2 changes: 1 addition & 1 deletion test/rails_band/active_support/event/cache_read_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class CacheReadTest < ActionDispatch::IntegrationTest
test 'returns key' do
get "/users/#{@user.id}/cache"

assert_equal @user.id, @event.key
assert_equal "key_#{@user.id}", @event.key
end

if Gem::Version.new(Rails.version) >= Gem::Version.new('6.1')
Expand Down

0 comments on commit b5e2b4c

Please sign in to comment.