rails-brotli-cache 0.3.11 → 0.3.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rails-brotli-cache/store.rb +21 -15
- data/lib/rails-brotli-cache/version.rb +1 -1
- data/spec/rails-brotli-cache/store_spec.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b682e9036d04afd87ca6369b612d524f65cf698ad53f23f06828d7e74690cd3a
|
4
|
+
data.tar.gz: 55a11863fc1e5027be392685beb2cdcb39ed12ea3b66f2761dc4ecfacea49eaa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bfc5e4b2224c5525c91ec7061263dac04cb6f4d0b045000977cd9c1ca90bcf2e07579e08083c4fc3621760b4cc887645c4408d0695da6a98dc54a170a6200f0d
|
7
|
+
data.tar.gz: 2fc5a1e3773b7d310e4b34b46f9209169dab055f02a8cbd7403ad8db467c399a517c7ca66d3a69e0feb89109a0596c8c1a9cd91f24ac533b05890921f6d7bfba
|
@@ -23,22 +23,22 @@ module RailsBrotliCache
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def fetch(name, options = nil, &block)
|
26
|
-
|
27
|
-
|
28
|
-
if value.present? && !options&.fetch(:force, false) == true
|
29
|
-
return value
|
30
|
-
end
|
31
|
-
|
32
|
-
if block_given?
|
33
|
-
value = block.call
|
34
|
-
write(name, value, options)
|
26
|
+
options ||= {}
|
35
27
|
|
36
|
-
|
37
|
-
elsif options && options[:force]
|
28
|
+
if !block_given? && options[:force]
|
38
29
|
raise ArgumentError, "Missing block: Calling `Cache#fetch` with `force: true` requires a block."
|
39
|
-
else
|
40
|
-
read(name, options)
|
41
30
|
end
|
31
|
+
|
32
|
+
uncompressed(
|
33
|
+
@core_store.fetch(cache_key(name), options.merge(compress: false)) do
|
34
|
+
if block_given?
|
35
|
+
compressed(block.call, options)
|
36
|
+
else
|
37
|
+
nil
|
38
|
+
end
|
39
|
+
end,
|
40
|
+
options
|
41
|
+
)
|
42
42
|
end
|
43
43
|
|
44
44
|
def write(name, value, options = nil)
|
@@ -62,6 +62,7 @@ module RailsBrotliCache
|
|
62
62
|
end
|
63
63
|
|
64
64
|
def write_multi(hash, options = nil)
|
65
|
+
options ||= {}
|
65
66
|
new_hash = hash.map do |key, val|
|
66
67
|
[
|
67
68
|
cache_key(key),
|
@@ -69,7 +70,10 @@ module RailsBrotliCache
|
|
69
70
|
]
|
70
71
|
end
|
71
72
|
|
72
|
-
@core_store.write_multi(
|
73
|
+
@core_store.write_multi(
|
74
|
+
new_hash,
|
75
|
+
options.merge(compress: false)
|
76
|
+
)
|
73
77
|
end
|
74
78
|
|
75
79
|
def read_multi(*names)
|
@@ -85,7 +89,9 @@ module RailsBrotliCache
|
|
85
89
|
options = names.extract_options!
|
86
90
|
names = names.map { |name| cache_key(name) }
|
87
91
|
|
88
|
-
@core_store.fetch_multi(
|
92
|
+
@core_store.fetch_multi(
|
93
|
+
*names, options.merge(compress: false)
|
94
|
+
) do |name|
|
89
95
|
compressed(yield(name), options)
|
90
96
|
end
|
91
97
|
end
|
@@ -19,9 +19,9 @@ describe RailsBrotliCache do
|
|
19
19
|
|
20
20
|
it "executes block only once" do
|
21
21
|
counter = 0
|
22
|
-
cache_store.fetch("
|
23
|
-
cache_store.fetch("
|
24
|
-
expect(cache_store.read("
|
22
|
+
cache_store.fetch("test-key") { counter += 1 }
|
23
|
+
cache_store.fetch("test-key") { counter += 1 }
|
24
|
+
expect(cache_store.read("test-key")).to eq 1
|
25
25
|
end
|
26
26
|
|
27
27
|
context "{ force: true }" do
|
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.3.
|
4
|
+
version: 0.3.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pawurb
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-05-
|
11
|
+
date: 2023-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|