From 4a552c3ab91e4005abcbf99a9531f84d4fd5485c Mon Sep 17 00:00:00 2001 From: Rajesh Sharma Date: Wed, 15 Jul 2020 00:05:15 +0530 Subject: [PATCH] Fix option not being passed with fetch_multi In redis cache store, options to `fetch_multi` are passed correctly to `write_multi` but not to `read_multi`. This causes cache always to be missed when passing `namespace` option to it. --- activesupport/CHANGELOG.md | 5 +++++ .../lib/active_support/cache/redis_cache_store.rb | 2 +- activesupport/test/cache/stores/redis_cache_store_test.rb | 8 ++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index 5bca1a8ab6..73dcacafba 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,3 +1,8 @@ +* Fixed issue in `ActiveSupport::Cache::RedisCacheStore` not passing options + to `read_multi` causing `fetch_multi` to not work properly + + *Rajesh Sharma* + * Fixed issue in `ActiveSupport::Cache::MemCacheStore` which caused duplicate compression, and caused the provided `compression_threshold` to not be respected. diff --git a/activesupport/lib/active_support/cache/redis_cache_store.rb b/activesupport/lib/active_support/cache/redis_cache_store.rb index c21a9c06c5..c36831b403 100644 --- a/activesupport/lib/active_support/cache/redis_cache_store.rb +++ b/activesupport/lib/active_support/cache/redis_cache_store.rb @@ -351,7 +351,7 @@ module ActiveSupport def read_multi_entries(names, **options) if mget_capable? - read_multi_mget(*names) + read_multi_mget(*names, **options) else super end diff --git a/activesupport/test/cache/stores/redis_cache_store_test.rb b/activesupport/test/cache/stores/redis_cache_store_test.rb index e6d96425e3..5ca3b13726 100644 --- a/activesupport/test/cache/stores/redis_cache_store_test.rb +++ b/activesupport/test/cache/stores/redis_cache_store_test.rb @@ -142,6 +142,14 @@ module ActiveSupport::Cache::RedisCacheStoreTests end end + def test_fetch_multi_with_namespace + assert_called_with(@cache.redis, :mget, ["custom-namespace:a", "custom-namespace:b", "custom-namespace:c"], returns: []) do + @cache.fetch_multi("a", "b", "c", namespace: "custom-namespace") do |key| + key * 2 + end + end + end + def test_fetch_multi_without_names assert_not_called(@cache.redis, :mget) do @cache.fetch_multi() { }