rails-brotli-cache 0.0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +34 -0
  3. data/.gitignore +9 -0
  4. data/README.md +91 -2
  5. data/Rakefile +5 -0
  6. data/docker-compose.yml.sample +11 -0
  7. data/lib/rails-brotli-cache/version.rb +3 -1
  8. data/lib/rails-brotli-cache.rb +69 -1
  9. data/rails-brotli-cache.gemspec +6 -2
  10. data/spec/dummy/Gemfile +45 -0
  11. data/spec/dummy/README.md +24 -0
  12. data/spec/dummy/Rakefile +6 -0
  13. data/spec/dummy/app/assets/config/manifest.js +2 -0
  14. data/spec/dummy/app/assets/images/.keep +0 -0
  15. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  16. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  17. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  18. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  19. data/spec/dummy/app/models/concerns/.keep +0 -0
  20. data/spec/dummy/app/views/layouts/application.html.erb +15 -0
  21. data/spec/dummy/bin/bundle +114 -0
  22. data/spec/dummy/bin/rails +4 -0
  23. data/spec/dummy/bin/rake +4 -0
  24. data/spec/dummy/bin/setup +25 -0
  25. data/spec/dummy/config/application.rb +37 -0
  26. data/spec/dummy/config/boot.rb +3 -0
  27. data/spec/dummy/config/credentials.yml.enc +1 -0
  28. data/spec/dummy/config/environment.rb +5 -0
  29. data/spec/dummy/config/environments/development.rb +41 -0
  30. data/spec/dummy/config/environments/production.rb +72 -0
  31. data/spec/dummy/config/environments/test.rb +50 -0
  32. data/spec/dummy/config/initializers/assets.rb +12 -0
  33. data/spec/dummy/config/initializers/content_security_policy.rb +25 -0
  34. data/spec/dummy/config/initializers/filter_parameter_logging.rb +8 -0
  35. data/spec/dummy/config/initializers/inflections.rb +16 -0
  36. data/spec/dummy/config/initializers/permissions_policy.rb +11 -0
  37. data/spec/dummy/config/locales/en.yml +33 -0
  38. data/spec/dummy/config/master.key +1 -0
  39. data/spec/dummy/config/puma.rb +43 -0
  40. data/spec/dummy/config/routes.rb +6 -0
  41. data/spec/dummy/config.ru +6 -0
  42. data/spec/dummy/lib/assets/.keep +0 -0
  43. data/spec/dummy/lib/tasks/.keep +0 -0
  44. data/spec/dummy/public/404.html +67 -0
  45. data/spec/dummy/public/422.html +67 -0
  46. data/spec/dummy/public/500.html +66 -0
  47. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  48. data/spec/dummy/public/apple-touch-icon.png +0 -0
  49. data/spec/dummy/public/favicon.ico +0 -0
  50. data/spec/dummy/public/robots.txt +1 -0
  51. data/spec/dummy/vendor/.keep +0 -0
  52. data/spec/fixtures/sample.json +1 -0
  53. data/spec/rails-brotli-cache/common_spec.rb +58 -0
  54. data/spec/rails-brotli-cache/redis_spec.rb +41 -0
  55. data/spec/spec_helper.rb +7 -0
  56. metadata +152 -8
  57. data/Gemfile.lock +0 -172
  58. data/lib/rails-brotli-cache/main.rb +0 -5
  59. data/spec/rails-brotli-cache/main_spec.rb +0 -10
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe RailsBrotliCache do
6
+ context "without prepending Rails.cache" do
7
+ describe "#fetch" do
8
+ it "stores value in the configured Rails.cache with a prefix" do
9
+ RailsBrotliCache.fetch("test-key") { 123 }
10
+ expect(RailsBrotliCache.read("test-key")).to eq 123
11
+ expect(Rails.cache.read("br-test-key")).to be_present
12
+ end
13
+
14
+ it "returns nil for missing entries if block is not provided" do
15
+ expect(RailsBrotliCache.fetch("missing-key")).to eq nil
16
+ end
17
+
18
+ context "{ force: true }" do
19
+ it "raises an error if block is not provided" do
20
+ expect {
21
+ RailsBrotliCache.fetch("missing-key", force: true)
22
+ }.to raise_error(ArgumentError)
23
+ end
24
+
25
+ it "always refreshes cached entry if block is provided" do
26
+
27
+ end
28
+ end
29
+ end
30
+
31
+ describe "#read and #write" do
32
+ it "reads values stored in Rails cache with a prefix" do
33
+ expect(RailsBrotliCache.read("test-key")).to eq nil
34
+ expect(RailsBrotliCache.write("test-key", 1234))
35
+ expect(RailsBrotliCache.read("test-key")).to eq 1234
36
+ end
37
+ end
38
+
39
+ describe "#delete" do
40
+ it "removes the previously stored cache entry" do
41
+ expect(RailsBrotliCache.write("test-key", 1234))
42
+ expect(RailsBrotliCache.read("test-key")).to eq 1234
43
+ RailsBrotliCache.delete("test-key")
44
+ expect(RailsBrotliCache.read("test-key")).to eq nil
45
+ end
46
+ end
47
+
48
+ describe "disable_prefix!" do
49
+ it "saves brotli cache entries without `br-` prefix" do
50
+ RailsBrotliCache.disable_prefix!
51
+ RailsBrotliCache.fetch("test-key") { 123 }
52
+ expect(Rails.cache.read("br-test-key")).to eq nil
53
+ expect(Rails.cache.read("test-key")).to be_present
54
+ RailsBrotliCache.class_variable_set(:@@prefix, "br-")
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'redis'
5
+
6
+ return unless ENV["TEST_CACHE_STORE"] == "redis_cache_store"
7
+ $redis = Redis.new
8
+
9
+ describe RailsBrotliCache do
10
+ it "sets correct cache store based on ENV variable" do
11
+ expect(Rails.cache.class).to eq ActiveSupport::Cache::RedisCacheStore
12
+ end
13
+
14
+ describe "#fetch" do
15
+ it "stores value in the configured redis cache store" do
16
+ RailsBrotliCache.fetch("test-key") { 123 }
17
+ expect($redis.get("br-test-key")).to be_present
18
+ end
19
+ end
20
+
21
+ let(:json) do
22
+ File.read('spec/fixtures/sample.json')
23
+ end
24
+
25
+ it "applies more efficient brotli compression" do
26
+ Rails.cache.write("gz-test-key", json)
27
+ RailsBrotliCache.write("test-key", json)
28
+ expect($redis.get("gz-test-key").size > $redis.get("br-test-key").size).to eq true
29
+ end
30
+
31
+ context "payloads smaller then 1kb" do
32
+ before do
33
+ # expect(Brotli).not_to receive(:deflate)
34
+ end
35
+
36
+ it "does not apply compression" do
37
+ RailsBrotliCache.write("test-key", 123)
38
+ expect(RailsBrotliCache.read("test-key")).to eq 123
39
+ end
40
+ end
41
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,14 @@
1
1
  require 'rubygems'
2
2
  require 'bundler/setup'
3
+ require 'rails'
4
+
3
5
  require_relative '../lib/rails-brotli-cache'
6
+ require_relative '../spec/dummy/config/environment'
7
+ ENV['RAILS_ROOT'] ||= "#{File.dirname(__FILE__)}../../../spec/dummy"
4
8
 
5
9
  RSpec.configure do |config|
10
+ config.before(:each) do
11
+ Rails.cache.clear
12
+ end
6
13
  end
7
14
 
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.0.1
4
+ version: 0.1.1
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-09 00:00:00.000000000 Z
11
+ date: 2023-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: brotli
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rspec
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -38,25 +52,111 @@ dependencies:
38
52
  - - ">="
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: redis
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: dalli
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
41
97
  description: " rails-brotli-cache allows to reduce storage needed for Rails cache
42
- by using Brotli compression which can produce outputs smaller by ~20% "
98
+ by using Brotli compression which can produce outputs smaller by ~20%. "
43
99
  email:
44
100
  - contact@pawelurbanek.com
45
101
  executables: []
46
102
  extensions: []
47
103
  extra_rdoc_files: []
48
104
  files:
105
+ - ".circleci/config.yml"
49
106
  - ".gitignore"
50
107
  - Gemfile
51
- - Gemfile.lock
52
108
  - LICENSE.txt
53
109
  - README.md
54
110
  - Rakefile
111
+ - docker-compose.yml.sample
55
112
  - lib/rails-brotli-cache.rb
56
- - lib/rails-brotli-cache/main.rb
57
113
  - lib/rails-brotli-cache/version.rb
58
114
  - rails-brotli-cache.gemspec
59
- - spec/rails-brotli-cache/main_spec.rb
115
+ - spec/dummy/Gemfile
116
+ - spec/dummy/README.md
117
+ - spec/dummy/Rakefile
118
+ - spec/dummy/app/assets/config/manifest.js
119
+ - spec/dummy/app/assets/images/.keep
120
+ - spec/dummy/app/assets/stylesheets/application.css
121
+ - spec/dummy/app/controllers/application_controller.rb
122
+ - spec/dummy/app/controllers/concerns/.keep
123
+ - spec/dummy/app/helpers/application_helper.rb
124
+ - spec/dummy/app/models/concerns/.keep
125
+ - spec/dummy/app/views/layouts/application.html.erb
126
+ - spec/dummy/bin/bundle
127
+ - spec/dummy/bin/rails
128
+ - spec/dummy/bin/rake
129
+ - spec/dummy/bin/setup
130
+ - spec/dummy/config.ru
131
+ - spec/dummy/config/application.rb
132
+ - spec/dummy/config/boot.rb
133
+ - spec/dummy/config/credentials.yml.enc
134
+ - spec/dummy/config/environment.rb
135
+ - spec/dummy/config/environments/development.rb
136
+ - spec/dummy/config/environments/production.rb
137
+ - spec/dummy/config/environments/test.rb
138
+ - spec/dummy/config/initializers/assets.rb
139
+ - spec/dummy/config/initializers/content_security_policy.rb
140
+ - spec/dummy/config/initializers/filter_parameter_logging.rb
141
+ - spec/dummy/config/initializers/inflections.rb
142
+ - spec/dummy/config/initializers/permissions_policy.rb
143
+ - spec/dummy/config/locales/en.yml
144
+ - spec/dummy/config/master.key
145
+ - spec/dummy/config/puma.rb
146
+ - spec/dummy/config/routes.rb
147
+ - spec/dummy/lib/assets/.keep
148
+ - spec/dummy/lib/tasks/.keep
149
+ - spec/dummy/public/404.html
150
+ - spec/dummy/public/422.html
151
+ - spec/dummy/public/500.html
152
+ - spec/dummy/public/apple-touch-icon-precomposed.png
153
+ - spec/dummy/public/apple-touch-icon.png
154
+ - spec/dummy/public/favicon.ico
155
+ - spec/dummy/public/robots.txt
156
+ - spec/dummy/vendor/.keep
157
+ - spec/fixtures/sample.json
158
+ - spec/rails-brotli-cache/common_spec.rb
159
+ - spec/rails-brotli-cache/redis_spec.rb
60
160
  - spec/spec_helper.rb
61
161
  homepage: https://github.com/pawurb/rails-brotli-cache
62
162
  licenses:
@@ -80,7 +180,51 @@ requirements: []
80
180
  rubygems_version: 3.1.6
81
181
  signing_key:
82
182
  specification_version: 4
83
- summary: Rails cache using Brotli compression algorithm
183
+ summary: Rails cache using Brotli algorithm offers better compression and performance.
84
184
  test_files:
85
- - spec/rails-brotli-cache/main_spec.rb
185
+ - spec/dummy/Gemfile
186
+ - spec/dummy/README.md
187
+ - spec/dummy/Rakefile
188
+ - spec/dummy/app/assets/config/manifest.js
189
+ - spec/dummy/app/assets/images/.keep
190
+ - spec/dummy/app/assets/stylesheets/application.css
191
+ - spec/dummy/app/controllers/application_controller.rb
192
+ - spec/dummy/app/controllers/concerns/.keep
193
+ - spec/dummy/app/helpers/application_helper.rb
194
+ - spec/dummy/app/models/concerns/.keep
195
+ - spec/dummy/app/views/layouts/application.html.erb
196
+ - spec/dummy/bin/bundle
197
+ - spec/dummy/bin/rails
198
+ - spec/dummy/bin/rake
199
+ - spec/dummy/bin/setup
200
+ - spec/dummy/config.ru
201
+ - spec/dummy/config/application.rb
202
+ - spec/dummy/config/boot.rb
203
+ - spec/dummy/config/credentials.yml.enc
204
+ - spec/dummy/config/environment.rb
205
+ - spec/dummy/config/environments/development.rb
206
+ - spec/dummy/config/environments/production.rb
207
+ - spec/dummy/config/environments/test.rb
208
+ - spec/dummy/config/initializers/assets.rb
209
+ - spec/dummy/config/initializers/content_security_policy.rb
210
+ - spec/dummy/config/initializers/filter_parameter_logging.rb
211
+ - spec/dummy/config/initializers/inflections.rb
212
+ - spec/dummy/config/initializers/permissions_policy.rb
213
+ - spec/dummy/config/locales/en.yml
214
+ - spec/dummy/config/master.key
215
+ - spec/dummy/config/puma.rb
216
+ - spec/dummy/config/routes.rb
217
+ - spec/dummy/lib/assets/.keep
218
+ - spec/dummy/lib/tasks/.keep
219
+ - spec/dummy/public/404.html
220
+ - spec/dummy/public/422.html
221
+ - spec/dummy/public/500.html
222
+ - spec/dummy/public/apple-touch-icon-precomposed.png
223
+ - spec/dummy/public/apple-touch-icon.png
224
+ - spec/dummy/public/favicon.ico
225
+ - spec/dummy/public/robots.txt
226
+ - spec/dummy/vendor/.keep
227
+ - spec/fixtures/sample.json
228
+ - spec/rails-brotli-cache/common_spec.rb
229
+ - spec/rails-brotli-cache/redis_spec.rb
86
230
  - spec/spec_helper.rb
data/Gemfile.lock DELETED
@@ -1,172 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- rails-brotli-cache (0.0.1)
5
- rails
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- actioncable (7.0.4.3)
11
- actionpack (= 7.0.4.3)
12
- activesupport (= 7.0.4.3)
13
- nio4r (~> 2.0)
14
- websocket-driver (>= 0.6.1)
15
- actionmailbox (7.0.4.3)
16
- actionpack (= 7.0.4.3)
17
- activejob (= 7.0.4.3)
18
- activerecord (= 7.0.4.3)
19
- activestorage (= 7.0.4.3)
20
- activesupport (= 7.0.4.3)
21
- mail (>= 2.7.1)
22
- net-imap
23
- net-pop
24
- net-smtp
25
- actionmailer (7.0.4.3)
26
- actionpack (= 7.0.4.3)
27
- actionview (= 7.0.4.3)
28
- activejob (= 7.0.4.3)
29
- activesupport (= 7.0.4.3)
30
- mail (~> 2.5, >= 2.5.4)
31
- net-imap
32
- net-pop
33
- net-smtp
34
- rails-dom-testing (~> 2.0)
35
- actionpack (7.0.4.3)
36
- actionview (= 7.0.4.3)
37
- activesupport (= 7.0.4.3)
38
- rack (~> 2.0, >= 2.2.0)
39
- rack-test (>= 0.6.3)
40
- rails-dom-testing (~> 2.0)
41
- rails-html-sanitizer (~> 1.0, >= 1.2.0)
42
- actiontext (7.0.4.3)
43
- actionpack (= 7.0.4.3)
44
- activerecord (= 7.0.4.3)
45
- activestorage (= 7.0.4.3)
46
- activesupport (= 7.0.4.3)
47
- globalid (>= 0.6.0)
48
- nokogiri (>= 1.8.5)
49
- actionview (7.0.4.3)
50
- activesupport (= 7.0.4.3)
51
- builder (~> 3.1)
52
- erubi (~> 1.4)
53
- rails-dom-testing (~> 2.0)
54
- rails-html-sanitizer (~> 1.1, >= 1.2.0)
55
- activejob (7.0.4.3)
56
- activesupport (= 7.0.4.3)
57
- globalid (>= 0.3.6)
58
- activemodel (7.0.4.3)
59
- activesupport (= 7.0.4.3)
60
- activerecord (7.0.4.3)
61
- activemodel (= 7.0.4.3)
62
- activesupport (= 7.0.4.3)
63
- activestorage (7.0.4.3)
64
- actionpack (= 7.0.4.3)
65
- activejob (= 7.0.4.3)
66
- activerecord (= 7.0.4.3)
67
- activesupport (= 7.0.4.3)
68
- marcel (~> 1.0)
69
- mini_mime (>= 1.1.0)
70
- activesupport (7.0.4.3)
71
- concurrent-ruby (~> 1.0, >= 1.0.2)
72
- i18n (>= 1.6, < 2)
73
- minitest (>= 5.1)
74
- tzinfo (~> 2.0)
75
- builder (3.2.4)
76
- concurrent-ruby (1.2.2)
77
- crass (1.0.6)
78
- date (3.3.3)
79
- diff-lcs (1.5.0)
80
- erubi (1.12.0)
81
- globalid (1.1.0)
82
- activesupport (>= 5.0)
83
- i18n (1.13.0)
84
- concurrent-ruby (~> 1.0)
85
- loofah (2.20.0)
86
- crass (~> 1.0.2)
87
- nokogiri (>= 1.5.9)
88
- mail (2.8.1)
89
- mini_mime (>= 0.1.1)
90
- net-imap
91
- net-pop
92
- net-smtp
93
- marcel (1.0.2)
94
- method_source (1.0.0)
95
- mini_mime (1.1.2)
96
- mini_portile2 (2.8.2)
97
- minitest (5.18.0)
98
- net-imap (0.3.4)
99
- date
100
- net-protocol
101
- net-pop (0.1.2)
102
- net-protocol
103
- net-protocol (0.2.1)
104
- timeout
105
- net-smtp (0.3.3)
106
- net-protocol
107
- nio4r (2.5.9)
108
- nokogiri (1.14.3)
109
- mini_portile2 (~> 2.8.0)
110
- racc (~> 1.4)
111
- racc (1.6.2)
112
- rack (2.2.7)
113
- rack-test (2.1.0)
114
- rack (>= 1.3)
115
- rails (7.0.4.3)
116
- actioncable (= 7.0.4.3)
117
- actionmailbox (= 7.0.4.3)
118
- actionmailer (= 7.0.4.3)
119
- actionpack (= 7.0.4.3)
120
- actiontext (= 7.0.4.3)
121
- actionview (= 7.0.4.3)
122
- activejob (= 7.0.4.3)
123
- activemodel (= 7.0.4.3)
124
- activerecord (= 7.0.4.3)
125
- activestorage (= 7.0.4.3)
126
- activesupport (= 7.0.4.3)
127
- bundler (>= 1.15.0)
128
- railties (= 7.0.4.3)
129
- rails-dom-testing (2.0.3)
130
- activesupport (>= 4.2.0)
131
- nokogiri (>= 1.6)
132
- rails-html-sanitizer (1.5.0)
133
- loofah (~> 2.19, >= 2.19.1)
134
- railties (7.0.4.3)
135
- actionpack (= 7.0.4.3)
136
- activesupport (= 7.0.4.3)
137
- method_source
138
- rake (>= 12.2)
139
- thor (~> 1.0)
140
- zeitwerk (~> 2.5)
141
- rake (13.0.6)
142
- rspec (3.12.0)
143
- rspec-core (~> 3.12.0)
144
- rspec-expectations (~> 3.12.0)
145
- rspec-mocks (~> 3.12.0)
146
- rspec-core (3.12.2)
147
- rspec-support (~> 3.12.0)
148
- rspec-expectations (3.12.3)
149
- diff-lcs (>= 1.2.0, < 2.0)
150
- rspec-support (~> 3.12.0)
151
- rspec-mocks (3.12.5)
152
- diff-lcs (>= 1.2.0, < 2.0)
153
- rspec-support (~> 3.12.0)
154
- rspec-support (3.12.0)
155
- thor (1.2.1)
156
- timeout (0.3.2)
157
- tzinfo (2.0.6)
158
- concurrent-ruby (~> 1.0)
159
- websocket-driver (0.7.5)
160
- websocket-extensions (>= 0.1.0)
161
- websocket-extensions (0.1.5)
162
- zeitwerk (2.6.8)
163
-
164
- PLATFORMS
165
- ruby
166
-
167
- DEPENDENCIES
168
- rails-brotli-cache!
169
- rspec
170
-
171
- BUNDLED WITH
172
- 2.1.4
@@ -1,5 +0,0 @@
1
- #encoding: UTF-8
2
- module RailsBrotliCache
3
- class Main
4
- end
5
- end
@@ -1,10 +0,0 @@
1
- #encoding: UTF-8
2
- require 'spec_helper'
3
-
4
- describe RailsBrotliCache::Main do
5
- describe "it" do
6
- it "works" do
7
- expect(true).to be true
8
- end
9
- end
10
- end