rails-brotli-cache 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -4
- data/lib/rails-brotli-cache/store.rb +7 -5
- data/lib/rails-brotli-cache/version.rb +1 -1
- data/spec/rails-brotli-cache/redis_spec.rb +25 -11
- data/spec/rails-brotli-cache/store_spec.rb +6 -8
- 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: ed8813c2a9849358eb4d1756cd39eda4acf03846ea166880b956d9c630a5f3ee
|
4
|
+
data.tar.gz: cdff030d0d6bdd7e2b7790c5aea0441ecc89e184165c38e899dc5abdc7f5c900
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5bf99730b2b31ed9591157fe75764fb15c17cf84cfd664d148a339e8552ed27dc62512cdff39f84552bc151aa4105d8720546eef38aa9e2da0552427d05ab86f
|
7
|
+
data.tar.gz: 7aa77827f595e73d55dc838ac8c6159a3f0f9138ed5bcdf57b2a0876060e01b66704dfd93f2eb8dc6502d109a0933f825bfc9d422858cbb786b03a75569f32d6
|
data/README.md
CHANGED
@@ -101,12 +101,13 @@ config.cache_store = RailsBrotliCache::Store.new(
|
|
101
101
|
)
|
102
102
|
```
|
103
103
|
|
104
|
-
Gem appends `br-` to the cache key names to prevent conflicts with previously saved cache entries. You can disable this behaviour by
|
105
|
-
|
106
|
-
`app/config/initializers/rails-brotli-cache.rb`
|
104
|
+
Gem appends `br-` to the cache key names to prevent conflicts with previously saved cache entries. You can disable this behaviour by passing `{ prefix: nil }` during initialization:
|
107
105
|
|
108
106
|
```ruby
|
109
|
-
|
107
|
+
config.cache_store = RailsBrotliCache::Store.new(
|
108
|
+
ActiveSupport::Cache::MemoryStore.new,
|
109
|
+
{ prefix: nil }
|
110
|
+
)
|
110
111
|
```
|
111
112
|
|
112
113
|
## Testing
|
@@ -9,9 +9,15 @@ module RailsBrotliCache
|
|
9
9
|
COMPRESS_QUALITY = ENV.fetch("BR_CACHE_COMPRESS_QUALITY", 5).to_i
|
10
10
|
MARK_BR_COMPRESSED = "\x02".b
|
11
11
|
|
12
|
+
attr_reader :core_store
|
13
|
+
|
12
14
|
def initialize(core_store, options = {})
|
13
15
|
@core_store = core_store
|
14
|
-
@prefix =
|
16
|
+
@prefix = if options.key?(:prefix)
|
17
|
+
options.fetch(:prefix)
|
18
|
+
else
|
19
|
+
"br-"
|
20
|
+
end
|
15
21
|
end
|
16
22
|
|
17
23
|
def fetch(name, options = nil, &block)
|
@@ -74,10 +80,6 @@ module RailsBrotliCache
|
|
74
80
|
@core_store.clear
|
75
81
|
end
|
76
82
|
|
77
|
-
def disable_prefix!
|
78
|
-
@prefix = nil
|
79
|
-
end
|
80
|
-
|
81
83
|
private
|
82
84
|
|
83
85
|
def cache_key(name)
|
@@ -5,9 +5,14 @@ require 'spec_helper'
|
|
5
5
|
return unless ENV['RAILS_CACHE_STORE'] == 'redis_cache_store'
|
6
6
|
|
7
7
|
describe RailsBrotliCache do
|
8
|
+
let(:options) do
|
9
|
+
{}
|
10
|
+
end
|
11
|
+
|
8
12
|
subject(:cache_store) do
|
9
13
|
RailsBrotliCache::Store.new(
|
10
|
-
ActiveSupport::Cache::RedisCacheStore.new(redis: $redis)
|
14
|
+
ActiveSupport::Cache::RedisCacheStore.new(redis: $redis),
|
15
|
+
options
|
11
16
|
)
|
12
17
|
end
|
13
18
|
|
@@ -28,16 +33,25 @@ describe RailsBrotliCache do
|
|
28
33
|
expect($redis.get("gz-test-key").size > $redis.get("br-test-key").size).to eq true
|
29
34
|
end
|
30
35
|
|
31
|
-
describe "disable_prefix
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
36
|
+
describe "disable_prefix" do
|
37
|
+
context "default prefix" do
|
38
|
+
it "appends 'br-' prefix" do
|
39
|
+
cache_store.fetch("test-key") { 123 }
|
40
|
+
expect($redis.get("test-key")).to eq nil
|
41
|
+
expect($redis.get("br-test-key")).to be_present
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "no prefix" do
|
46
|
+
let(:options) do
|
47
|
+
{ prefix: nil }
|
48
|
+
end
|
49
|
+
|
50
|
+
it "saves brotli cache entries without `br-` prefix" do
|
51
|
+
cache_store.fetch("test-key") { 123 }
|
52
|
+
expect($redis.get("br-test-key")).to eq nil
|
53
|
+
expect($redis.get("test-key")).to be_present
|
54
|
+
end
|
41
55
|
end
|
42
56
|
end
|
43
57
|
end
|
@@ -40,6 +40,12 @@ describe RailsBrotliCache do
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
+
describe "#core_store" do
|
44
|
+
it "exposes the underlying data store" do
|
45
|
+
expect(cache_store.core_store.class).to eq ActiveSupport::Cache::MemoryStore
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
43
49
|
describe "#read and #write" do
|
44
50
|
it "reads values stored in Rails cache with a prefix" do
|
45
51
|
expect(cache_store.read("test-key")).to eq nil
|
@@ -67,12 +73,4 @@ describe RailsBrotliCache do
|
|
67
73
|
expect(cache_store.read("test-key")).to eq nil
|
68
74
|
end
|
69
75
|
end
|
70
|
-
|
71
|
-
describe "disable_prefix!" do
|
72
|
-
it "saves brotli cache entries without `br-` prefix" do
|
73
|
-
cache_store.disable_prefix!
|
74
|
-
cache_store.fetch("test-key") { 123 }
|
75
|
-
cache_store.instance_variable_set(:@prefix, "br-")
|
76
|
-
end
|
77
|
-
end
|
78
76
|
end
|