diff --git a/app/models/solid_cache/entry.rb b/app/models/solid_cache/entry.rb index a3d3752..20ebcd9 100644 --- a/app/models/solid_cache/entry.rb +++ b/app/models/solid_cache/entry.rb @@ -116,7 +116,11 @@ def get_all_sql(key_hashes) @get_all_sql_binds ||= {} @get_all_sql_binds[key_hashes.count] ||= build_sql(where(key_hash: key_hashes).select(:key, :value)) else - @get_all_sql_no_binds ||= build_sql(where(key_hash: [ 1, 2 ]).select(:key, :value)).gsub("?, ?", "?") + if keys.size == 1 + @get_all_sql_no_binds_one_key ||= build_sql(where(key_hash: 1).select(:key, :value)) + else + @get_all_sql_no_binds_many_keys ||= build_sql(where(key_hash: [ 1, 2 ]).select(:key, :value)).gsub("?, ?", "?") + end end end diff --git a/test/unit/behaviors/cache_store_behavior.rb b/test/unit/behaviors/cache_store_behavior.rb index fdf50b4..8666c92 100644 --- a/test/unit/behaviors/cache_store_behavior.rb +++ b/test/unit/behaviors/cache_store_behavior.rb @@ -145,6 +145,7 @@ def test_read_multi @cache.write(other_key, "baz") @cache.write(SecureRandom.alphanumeric, "biz") assert_equal({ key => "bar", other_key => "baz" }, @cache.read_multi(key, other_key)) + assert_equal({ key => "bar" }, @cache.read_multi(key)) end def test_read_multi_empty_list