rails-brotli-cache 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e109b9b356474fb8085b1cceaa892695de997465db4c90872556f76419da8f86
4
- data.tar.gz: c8422310e9fed160052637a40dc7b1150b938c0f891b3b7b011eacdd11b8e4bb
3
+ metadata.gz: 6267cfdccacd5e402e500f1df681e16e8d0be371718e499d0abde30c64822dbd
4
+ data.tar.gz: 4648a2053526200a231c8cd36632715700a6ee197f672431ed2de1c150e036eb
5
5
  SHA512:
6
- metadata.gz: 6b435443fbf3a6a09baed87b124429e43dcd4d3fbd06cab175a15818b397285aeab96ad0694dc8a2f0e0d91c3478400ba0e3081045e93ca63e275e62626f0e0d
7
- data.tar.gz: 95af20d56721fbe1e9118b29a0fa1f7dc3fe5825d8c7ee04d77b783b96b405d6b1e765f4d8b63e8668d9414ca1e716cc010e3201d7a93340d35251ebd966f9e8
6
+ metadata.gz: 3dfdbc83794444e9be00962b4b5f6470f5c8803340cabbe3535f7143c87cc3bb21af6340d226e8b4b647cf6fd02a1318376daf98f4c50baa4707c70bcacca463
7
+ data.tar.gz: a8baf1bb1409642f3ea7e6251970a9fb8fbf1b3bbf6dade72a77f288d24de3f58fa2d00b36f24b4c82908a8f6e510564f9265b106297dcc1ddd7500b9c4f7306
@@ -109,16 +109,21 @@ module RailsBrotliCache
109
109
 
110
110
  def fetch_multi(*names)
111
111
  options = names.extract_options!
112
- names = names.map { |name| expanded_cache_key(name) }
112
+ expanded_names = names.map { |name| expanded_cache_key(name) }
113
113
  options = options.reverse_merge(@init_options)
114
114
 
115
- @core_store.fetch_multi(
116
- *names, options.merge(compress: false)
117
- ) do |name|
118
- compressed(yield(source_cache_key(name)), options)
119
- end.map do |key, val|
115
+ reads = core_store.send(:read_multi_entries, expanded_names, **options)
116
+ reads.map do |key, val|
120
117
  [source_cache_key(key), uncompressed(val, options)]
121
118
  end.to_h
119
+
120
+ writes = {}
121
+ ordered = names.index_with do |name|
122
+ reads.fetch(name) { writes[name] = yield(name) }
123
+ end
124
+
125
+ write_multi(writes)
126
+ ordered
122
127
  end
123
128
 
124
129
  def exist?(name, options = {})
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsBrotliCache
4
- VERSION = "0.6.1"
4
+ VERSION = "0.6.2"
5
5
  end
@@ -17,6 +17,11 @@ describe RailsBrotliCache do
17
17
  SecureRandom.hex(2048)
18
18
  end
19
19
 
20
+ after do
21
+ brotli_store.clear
22
+ standard_cache.clear
23
+ end
24
+
20
25
  describe "Brotli cache has the same API as #{cache_store_types[0].class}" do
21
26
  subject(:brotli_store) do
22
27
  RailsBrotliCache::Store.new(cache_store_types[0])
@@ -36,15 +41,15 @@ describe RailsBrotliCache do
36
41
 
37
42
  it "for #read and #write" do
38
43
  int_val = 123
39
- expect(brotli_store.write("int_val_key", big_enough_to_compress_value).class).to eq(standard_cache.write("int_val_key", big_enough_to_compress_value).class)
44
+ expect(brotli_store.write("int_val_key", int_val).class).to eq(standard_cache.write("int_val_key", int_val).class)
40
45
  expect(brotli_store.read("int_val_key")).to eq(standard_cache.read("int_val_key"))
41
46
 
42
- str_val = "str"
43
- expect(brotli_store.write("str_val_key", int_val).class).to eq(standard_cache.write("str_val_key", int_val).class)
47
+ str_val = big_enough_to_compress_value
48
+ expect(brotli_store.write("str_val_key", str_val).class).to eq(standard_cache.write("str_val_key", str_val).class)
44
49
  expect(brotli_store.read("str_val_key")).to eq(standard_cache.read("str_val_key"))
45
50
 
46
51
  complex_val = OpenStruct.new(a: 1, b: 2)
47
- expect(brotli_store.write("complex_val_key", int_val).class).to eq(standard_cache.write("complex_val_key", int_val).class)
52
+ expect(brotli_store.write("complex_val_key", complex_val).class).to eq(standard_cache.write("complex_val_key", complex_val).class)
48
53
  expect(brotli_store.read("complex_val_key")).to eq(standard_cache.read("complex_val_key"))
49
54
  end
50
55
 
@@ -66,8 +71,8 @@ describe RailsBrotliCache do
66
71
 
67
72
  it "for #write_multi and #read_multi" do
68
73
  values = {
69
- "key_1" => "val_1",
70
- "key_2" => big_enough_to_compress_value
74
+ "key_1" => big_enough_to_compress_value,
75
+ "key_2" => "val_2"
71
76
  }
72
77
 
73
78
  brotli_store.write_multi(values)
@@ -86,11 +91,11 @@ describe RailsBrotliCache do
86
91
  }
87
92
 
88
93
  brotli_store.fetch_multi("key_1", "key_2") do |key|
89
- "val_#{key.split('_').last}"
94
+ values[key]
90
95
  end
91
96
 
92
97
  standard_cache.fetch_multi("key_1", "key_2") do |key|
93
- "val_#{key.split('_').last}"
98
+ values[key]
94
99
  end
95
100
 
96
101
  expect(brotli_store.read("key_1")).to eq standard_cache.read("key_1")
@@ -112,8 +112,41 @@ describe RailsBrotliCache do
112
112
  }
113
113
  end
114
114
 
115
- it "works" do
115
+ it "works for store and reread" do
116
116
  expect(subject).to eq response
117
+
118
+ expect(cache_store.fetch_multi(*keys) do |key|
119
+ big_enough_to_compress_value + key
120
+ end).to eq response
121
+ end
122
+
123
+ context 'with a complex object that responds to #cache_key' do
124
+ subject do
125
+ cache_store.fetch_multi(*keys) do |key|
126
+ big_enough_to_compress_value + key.id
127
+ end
128
+ end
129
+
130
+ let(:keys) do
131
+ [
132
+ OpenStruct.new(cache_key: 'key_1', id: '12345'),
133
+ OpenStruct.new(cache_key: 'key_2', id: '54321')
134
+ ]
135
+ end
136
+ let(:response) do
137
+ {
138
+ keys[0] => big_enough_to_compress_value + '12345',
139
+ keys[1] => big_enough_to_compress_value + '54321'
140
+ }
141
+ end
142
+
143
+ it "works for store and reread" do
144
+ expect(subject).to eq response
145
+
146
+ expect(cache_store.fetch_multi(*keys) do |key|
147
+ big_enough_to_compress_value + key.id
148
+ end).to eq response
149
+ end
117
150
  end
118
151
  end
119
152
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-brotli-cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - pawurb
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-12 00:00:00.000000000 Z
11
+ date: 2023-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport