rails-brotli-cache 0.4.3 → 0.4.4
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 +12 -12
- data/lib/rails-brotli-cache/version.rb +1 -1
- data/spec/rails-brotli-cache/cache_keys_spec.rb +43 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 25d1a71b5e57f6f4c61612ff8c4cfb99d88aba2ed41b8f2436191c5c3e31904b
|
4
|
+
data.tar.gz: c9305dc9477b54c0072395d6e55ede962b9c311e907025c84d1ab5dc6fdf648d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b890c5e6b89cd6150fb5e965adecfa2963cce3de9ef4a474c70a66ba7e91f5dc21bba69eed3963e7ec84ddece396cc22be18150a2d0dc54fcf0ea92c4b7be877
|
7
|
+
data.tar.gz: 00d8463045555382d2d59bfff056470c6066042860332d30b9cd127166be119a70c28bf39241c144413a032a6fbc87127872945213d56fbb8bf52bf86d36a73c
|
@@ -46,7 +46,7 @@ module RailsBrotliCache
|
|
46
46
|
end
|
47
47
|
|
48
48
|
uncompressed(
|
49
|
-
@core_store.fetch(expanded_cache_key(name
|
49
|
+
@core_store.fetch(expanded_cache_key(name), options.merge(compress: false)) do
|
50
50
|
if block_given?
|
51
51
|
compressed(block.call, options)
|
52
52
|
else
|
@@ -62,7 +62,7 @@ module RailsBrotliCache
|
|
62
62
|
payload = compressed(value, options)
|
63
63
|
|
64
64
|
@core_store.write(
|
65
|
-
expanded_cache_key(name
|
65
|
+
expanded_cache_key(name),
|
66
66
|
payload,
|
67
67
|
options.merge(compress: false)
|
68
68
|
)
|
@@ -72,7 +72,7 @@ module RailsBrotliCache
|
|
72
72
|
options = (options || {}).reverse_merge(@init_options)
|
73
73
|
|
74
74
|
payload = @core_store.read(
|
75
|
-
expanded_cache_key(name
|
75
|
+
expanded_cache_key(name),
|
76
76
|
options
|
77
77
|
)
|
78
78
|
|
@@ -83,7 +83,7 @@ module RailsBrotliCache
|
|
83
83
|
options = (options || {}).reverse_merge(@init_options)
|
84
84
|
new_hash = hash.map do |key, val|
|
85
85
|
[
|
86
|
-
expanded_cache_key(key
|
86
|
+
expanded_cache_key(key),
|
87
87
|
compressed(val, options)
|
88
88
|
]
|
89
89
|
end
|
@@ -96,7 +96,7 @@ module RailsBrotliCache
|
|
96
96
|
|
97
97
|
def read_multi(*names)
|
98
98
|
options = names.extract_options!
|
99
|
-
names = names.map { |name| expanded_cache_key(name
|
99
|
+
names = names.map { |name| expanded_cache_key(name) }
|
100
100
|
options = options.reverse_merge(@init_options)
|
101
101
|
|
102
102
|
core_store.read_multi(*names, options).map do |key, val|
|
@@ -106,7 +106,7 @@ module RailsBrotliCache
|
|
106
106
|
|
107
107
|
def fetch_multi(*names)
|
108
108
|
options = names.extract_options!
|
109
|
-
names = names.map { |name| expanded_cache_key(name
|
109
|
+
names = names.map { |name| expanded_cache_key(name) }
|
110
110
|
options = options.reverse_merge(@init_options)
|
111
111
|
|
112
112
|
@core_store.fetch_multi(
|
@@ -117,11 +117,11 @@ module RailsBrotliCache
|
|
117
117
|
end
|
118
118
|
|
119
119
|
def exist?(name, options = {})
|
120
|
-
@core_store.exist?(expanded_cache_key(name
|
120
|
+
@core_store.exist?(expanded_cache_key(name), options)
|
121
121
|
end
|
122
122
|
|
123
123
|
def delete(name, options = {})
|
124
|
-
@core_store.delete(expanded_cache_key(name
|
124
|
+
@core_store.delete(expanded_cache_key(name), options)
|
125
125
|
end
|
126
126
|
|
127
127
|
def clear
|
@@ -129,11 +129,11 @@ module RailsBrotliCache
|
|
129
129
|
end
|
130
130
|
|
131
131
|
def increment(name, amount = 1, **options)
|
132
|
-
@core_store.increment(expanded_cache_key(name
|
132
|
+
@core_store.increment(expanded_cache_key(name), amount, **options)
|
133
133
|
end
|
134
134
|
|
135
135
|
def decrement(name, amount = 1, **options)
|
136
|
-
@core_store.decrement(expanded_cache_key(name
|
136
|
+
@core_store.decrement(expanded_cache_key(name), amount, **options)
|
137
137
|
end
|
138
138
|
|
139
139
|
def self.supports_cache_versioning?
|
@@ -174,8 +174,8 @@ module RailsBrotliCache
|
|
174
174
|
Marshal.load(serialized)
|
175
175
|
end
|
176
176
|
|
177
|
-
def expanded_cache_key(name
|
178
|
-
"#{@prefix}#{::ActiveSupport::Cache.expand_cache_key(name
|
177
|
+
def expanded_cache_key(name)
|
178
|
+
"#{@prefix}#{::ActiveSupport::Cache.expand_cache_key(name)}"
|
179
179
|
end
|
180
180
|
|
181
181
|
def source_cache_key(name)
|
@@ -15,13 +15,18 @@ describe RailsBrotliCache do
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
let(:options) do
|
19
|
+
{}
|
20
|
+
end
|
21
|
+
|
18
22
|
let(:redis_store) do
|
19
|
-
ActiveSupport::Cache::RedisCacheStore.new(redis: $redis)
|
23
|
+
ActiveSupport::Cache::RedisCacheStore.new({ redis: $redis }.merge(options))
|
20
24
|
end
|
21
25
|
|
22
26
|
let(:brotli_store) do
|
23
27
|
RailsBrotliCache::Store.new(
|
24
|
-
|
28
|
+
ActiveSupport::Cache::RedisCacheStore.new(redis: $redis),
|
29
|
+
options
|
25
30
|
)
|
26
31
|
end
|
27
32
|
|
@@ -49,6 +54,42 @@ describe RailsBrotliCache do
|
|
49
54
|
brotli_store.fetch([:views, "controller/action", collection]) { 123 }
|
50
55
|
expect($redis.get("views/controller/action/post/1/post/2")).to be_present
|
51
56
|
expect($redis.get("br-views/controller/action/post/1/post/2")).to be_present
|
57
|
+
expect(brotli_store.read([:views, "controller/action", collection])).to eq 123
|
58
|
+
end
|
59
|
+
|
60
|
+
context "custom namespace string is not duplicated" do
|
61
|
+
let(:options) do
|
62
|
+
{
|
63
|
+
namespace: "myapp"
|
64
|
+
}
|
65
|
+
end
|
66
|
+
|
67
|
+
it "activemodel object keys" do
|
68
|
+
post_1 = Post.new(id: 1)
|
69
|
+
redis_store.fetch(post_1) { 123 }
|
70
|
+
brotli_store.fetch(post_1) { 123 }
|
71
|
+
expect($redis.get("myapp:post/1")).to be_present
|
72
|
+
expect($redis.get("myapp:br-post/1")).to be_present
|
73
|
+
expect(brotli_store.read(post_1)).to eq 123
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context "custom namespace proc" do
|
78
|
+
@@counter = 0
|
79
|
+
let(:options) do
|
80
|
+
{
|
81
|
+
namespace: -> { "myapp" }
|
82
|
+
}
|
83
|
+
end
|
84
|
+
|
85
|
+
it "activemodel object keys" do
|
86
|
+
post_1 = Post.new(id: 1)
|
87
|
+
redis_store.fetch(post_1) { 123 }
|
88
|
+
brotli_store.fetch(post_1) { 123 }
|
89
|
+
expect($redis.get("myapp:post/1")).to be_present
|
90
|
+
expect($redis.get("myapp:br-post/1")).to be_present
|
91
|
+
expect(brotli_store.read(post_1)).to eq 123
|
92
|
+
end
|
52
93
|
end
|
53
94
|
end
|
54
95
|
end
|