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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 44c290253b45a487daecc85b45026bd7d3f140644095c7f15cfb67dcee1299b8
4
- data.tar.gz: d37323f26dda367401403714eb094dfd6a0e3274b7d88cb81eb2d5380ce91979
3
+ metadata.gz: ed8813c2a9849358eb4d1756cd39eda4acf03846ea166880b956d9c630a5f3ee
4
+ data.tar.gz: cdff030d0d6bdd7e2b7790c5aea0441ecc89e184165c38e899dc5abdc7f5c900
5
5
  SHA512:
6
- metadata.gz: 537fe80385fbc5f8d339b56f789aaeefc45e2589456e2fb522afdcb3656af6254951654a0524b5136ad3cb25fb23c092ea6bc027377c39ed9f52645886a94fc0
7
- data.tar.gz: a6057e3a65505003ee849e9f0a38a12963a78468c32275ca0e1d70ead490ddba7663d2a1d65b4359ca7fb626b27e15fc8552d77d9d35c353bbdf77f933fdb277
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 adding the following initializer file:
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
- Rails.cache.disable_prefix!
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 = "br-"
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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsBrotliCache
4
- VERSION = "0.2.1"
4
+ VERSION = "0.2.2"
5
5
  end
@@ -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!" do
32
- it "saves brotli cache entries without `br-` prefix" do
33
- cache_store.fetch("test-key") { 123 }
34
- expect($redis.get("test-key")).to eq nil
35
- expect($redis.get("br-test-key")).to be_present
36
- cache_store.disable_prefix!
37
- cache_store.fetch("test-key-2") { 123 }
38
- expect($redis.get("br-test-key-2")).to eq nil
39
- expect($redis.get("test-key-2")).to be_present
40
- cache_store.instance_variable_set(:@prefix, "br-")
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-brotli-cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - pawurb