Skip to content

Commit

Permalink
Cache read_multi results in LocalStore when it exists
Browse files Browse the repository at this point in the history
  • Loading branch information
chendo committed Dec 13, 2012
1 parent 2043dd2 commit 6cefc8b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/active_support/cache/dalli_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ def read_multi(*names)
results.inject({}) do |memo, (inner, _)|
entry = results[inner]
# NB Backwards data compatibility, to be removed at some point
memo[mapping[inner]] = (entry.is_a?(ActiveSupport::Cache::Entry) ? entry.value : entry)
value = (entry.is_a?(ActiveSupport::Cache::Entry) ? entry.value : entry)
memo[mapping[inner]] = value
local_cache.write_entry(inner, value, options) if local_cache
memo
end
end
Expand Down
22 changes: 21 additions & 1 deletion test/test_active_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,27 @@ def cache_key
end
end

should 'support read_multi with LocalCache' do
with_activesupport do
memcached do
connect
x = rand_key
y = rand_key
assert_equal({}, @dalli.read_multi(x, y))
@dalli.write(x, '123')
@dalli.write(y, 123)

@dalli.with_local_cache do
assert_equal({ x => '123', y => 123 }, @dalli.read_multi(x, y))
Dalli::Client.any_instance.expects(:get).with(any_parameters).never

dres = @dalli.read(x)
assert_equal dres, '123'
end
end
end
end

should 'support read, write and delete' do
with_activesupport do
memcached do
Expand Down Expand Up @@ -152,7 +173,6 @@ def cache_key
memcached do
connect
y = rand_key.to_s

@dalli.with_local_cache do
Dalli::Client.any_instance.expects(:get).with(y, {}).once.returns(123)
dres = @dalli.read(y)
Expand Down

0 comments on commit 6cefc8b

Please sign in to comment.