Skip to content

Commit

Permalink
Pass a list instead of an Array to #read_multi.
Browse files Browse the repository at this point in the history
  • Loading branch information
DouweM committed Oct 8, 2014
1 parent 142931f commit c6b2e16
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
5 changes: 3 additions & 2 deletions lib/rabl/cache_engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ def write(key, value, options={})
end
end

def read_multi(keys, cache_options = {})
def read_multi(*keys)
options = keys.extract_options!
if defined?(Rails)
Rails.cache.read_multi(keys, cache_options)
Rails.cache.read_multi(*keys, cache_options)
else
keys.inject({}) { |hash, key| hash[key] = nil; hash }
end
Expand Down
5 changes: 3 additions & 2 deletions lib/rabl/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def to_hash(options={})
result = builder.build(data, options)
elsif is_collection?(data) # collection @users
result = if template_cache_configured? && Rabl.configuration.use_read_multi
read_multi(data, options)
read_multi(*data, options)
else
data.map { |object| builder.build(object, options) }
end
Expand Down Expand Up @@ -330,7 +330,8 @@ def cache_results(&block)

# Uses read_multi to render a collection of cache keys,
# falling back to a normal render in the event of a miss.
def read_multi(data, options={})
def read_multi(*data)
options = data.extract_options!
builder = Rabl::MultiBuilder.new(data, options)
builder.to_a
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rabl/multi_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def cache_results
mutable_keys = @cache_key_to_engine.keys.map { |k| k.dup }
return {} if mutable_keys.empty?

Rabl.configuration.cache_engine.read_multi(mutable_keys)
Rabl.configuration.cache_engine.read_multi(*mutable_keys)
end

# Maps the results from the cache back to the builders
Expand Down
2 changes: 1 addition & 1 deletion test/multi_builder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
end

asserts "uses read_multi to find all of the cached values with keys" do
mock(Rabl.configuration.cache_engine).read_multi(['cache_key']).returns({})
mock(Rabl.configuration.cache_engine).read_multi('cache_key').returns({})
topic.send(:cache_results)
end
end
Expand Down

0 comments on commit c6b2e16

Please sign in to comment.