Skip to content

Commit

Permalink
Uncompress and unprefix fetch multi (#15)
Browse files Browse the repository at this point in the history
* Uncompress and unprefix fetch multi

* Pass source key to the block
  • Loading branch information
marcoadkins committed Oct 12, 2023
1 parent 2f1b3fd commit 6ff2ce6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
6 changes: 4 additions & 2 deletions lib/rails-brotli-cache/store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,10 @@ def fetch_multi(*names)
@core_store.fetch_multi(
*names, options.merge(compress: false)
) do |name|
compressed(yield(name), options)
end
compressed(yield(source_cache_key(name)), options)
end.map do |key, val|
[source_cache_key(key), uncompressed(val, options)]
end.to_h
end

def exist?(name, options = {})
Expand Down
17 changes: 15 additions & 2 deletions spec/rails-brotli-cache/store_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,22 @@ def to_param
end

describe "fetch_multi" do
subject do
cache_store.fetch_multi(*keys) do |key|
big_enough_to_compress_value + key
end
end

let(:keys) { %w[key_1 key_2] }
let(:response) do
{
'key_1' => big_enough_to_compress_value + 'key_1',
'key_2' => big_enough_to_compress_value + 'key_2'
}
end

it "works" do
cache_store.fetch_multi("key_1", "key_2", expires_in: 5.seconds) { big_enough_to_compress_value }
expect(cache_store.read("key_1")).to eq big_enough_to_compress_value
expect(subject).to eq response
end
end

Expand Down

0 comments on commit 6ff2ce6

Please sign in to comment.