Skip to content

Commit

Permalink
Alter behavior of read_multi to match ActiveSupport::Cache::Store
Browse files Browse the repository at this point in the history
In the base implementation of ActiveSupport::Cache::Store (and all other
implementing stores), an array of strings passed as argument to
read_multi is treated as a single key. In DalliStore, it is treated as
several keys. This alters the spec and implementation of DalliStore's
read_multi to match ActiveSupport::Cache::Store.
  • Loading branch information
Frank Macreery committed May 6, 2013
1 parent 7e47a9e commit 2868c6b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 0 additions & 1 deletion lib/active_support/cache/dalli_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ def delete(name, options=nil)
# servers for all keys. Keys must be Strings.
def read_multi(*names)
names.extract_options!
names = names.flatten
mapping = names.inject({}) { |memo, name| memo[expanded_key(name)] = name; memo }
instrument(:read_multi, names) do
results = {}
Expand Down
6 changes: 4 additions & 2 deletions test/test_active_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ def cache_key
assert_equal({}, @dalli.read_multi([x, y]))
@dalli.write(x, '123')
@dalli.write(y, 123)
assert_equal({ x => '123', y => 123 }, @dalli.read_multi([x, y]))
assert_equal({}, @dalli.read_multi([x, y]))
@dalli.write([x, y], '123')
assert_equal({ [x, y] => '123' }, @dalli.read_multi([x, y]))
end
end
end
Expand Down Expand Up @@ -347,7 +349,7 @@ def cache_key
map.each_pair do |k, v|
assert_equal true, @dalli.write(k, v)
end
assert_equal map, @dalli.read_multi(map.keys)
assert_equal map, @dalli.read_multi(*(map.keys))
end
end
end
Expand Down

0 comments on commit 2868c6b

Please sign in to comment.