rails-brotli-cache 0.3.12 → 0.3.14
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 +14 -14
- data/lib/rails-brotli-cache/version.rb +1 -1
- data/spec/rails-brotli-cache/store_spec.rb +9 -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: cceeb82eb8c194ea2b8acd9fbdcf5a55d53fd6dbdf0f4f9aaf20ae2577fcab2c
|
4
|
+
data.tar.gz: 6c2bcade2408e81a303091e782d01239c625c288f63def2a6c40618fedf2bc4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04bc2568e39f8f398f5cd71fd169570a07ec972d506baf33202738145e48009f6064da385b521671627e058c7fec1115db28b9dd806c0cc123ae0811af9dce5e
|
7
|
+
data.tar.gz: f62f95df44c1acb1ceb734299291a68323a7c093b15f7762651faf43a49f83d5e7d80054444d2d63ff38bb2758fc2909836b15b93b50f54c3e0638b2c5456ec1
|
@@ -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)
|
@@ -130,7 +130,7 @@ module RailsBrotliCache
|
|
130
130
|
return value if value.is_a?(Integer)
|
131
131
|
serialized = Marshal.dump(value)
|
132
132
|
|
133
|
-
if serialized.bytesize >= COMPRESS_THRESHOLD && !options.fetch(:compress) == false
|
133
|
+
if serialized.bytesize >= COMPRESS_THRESHOLD && !options.fetch(:compress, true) == false
|
134
134
|
compressor = compressor_class(options, default: @compressor_class)
|
135
135
|
compressed_payload = compressor.deflate(serialized)
|
136
136
|
if compressed_payload.bytesize < serialized.bytesize
|
@@ -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
|
@@ -38,6 +38,12 @@ describe RailsBrotliCache do
|
|
38
38
|
expect(cache_store.read("forced-key")).to eq 2
|
39
39
|
end
|
40
40
|
end
|
41
|
+
|
42
|
+
it "stores value in the configured Rails.cache when options passed" do
|
43
|
+
big_enough_to_compress_value = SecureRandom.hex(2048)
|
44
|
+
cache_store.fetch("test-key", expires_in: 5.seconds) { big_enough_to_compress_value }
|
45
|
+
expect(cache_store.read("test-key")).to eq big_enough_to_compress_value
|
46
|
+
end
|
41
47
|
end
|
42
48
|
|
43
49
|
describe "#increment and #decrement" 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.14
|
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-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|