rails-brotli-cache 0.3.4 → 0.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 412dc55dcd3f00210f9c090472b3dfcf10bedba7c2882015a74349797bfe4197
4
- data.tar.gz: 7f8085d5fc354f899db174cf6080ea5f03a06f97a714afbb56b9f05aee801a2e
3
+ metadata.gz: 2d61874a96a2402ac69abd17762f98531de0a5b2c2749447f3c34d03dc76b57b
4
+ data.tar.gz: dff930d1caf6e592d207db48ffb175ebcd06bc59d228a9b5a78e3185672ee72d
5
5
  SHA512:
6
- metadata.gz: 539de77bdcf9cd35b99023859a8e9c8d4cb25c99161ea32699a11818ec45f38165bf29bc7a738fb57e6ee39c8774460b9e2b8a626e77cbf1ed597b3178e6e0c4
7
- data.tar.gz: 18326136e7fe619a5af79e6bb3ea803a0656a06aacdf624c7c5f8fd2ef7d175a1a9b24583675b96155e5dd3fc8e838b2dee4bdb3100366c6a799e7462c216c9d
6
+ metadata.gz: f3d3cda105423ff917c8b7bd1785cbad9c4577fe773d9573995f1341a6fb3093538e67febe45e6c4449c80398c5edfc95770c7b968fae78524f55bdefa92bd92
7
+ data.tar.gz: b705720c468a0c85e2b7cf3ff72a2c320ab0beefa3d0889c862b716d1d8d26146e5f2afe9f08bb2101e0ddc07e313cf06a85095f6b778ab8d11ef3f4977a4783
data/.gitignore CHANGED
@@ -9,4 +9,5 @@ docker-compose.yml
9
9
  .byebug_history
10
10
  spec/dummy/log/
11
11
  spec/dummy/tmp/
12
+ tmp/
12
13
 
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  This gem enables support for compressing Ruby on Rails cache entries using the [Brotli compression algorithm](https://github.com/google/brotli). `RailsBrotliCache::Store` offers better compression and performance compared to the default `Rails.cache` Gzip, regardless of the underlying data store. The gem also allows specifying any custom compression algorithm instead of Brotli.
4
4
 
5
+ I'm currently working on a post describing the gem in more detail. You can subscribe to [my blog's mailing list](https://eepurl.com/dhuFg5) or [follow me on Twitter](https://twitter.com/_pawurb) to get notified when it's out.
6
+
5
7
  ## Benchmarks
6
8
 
7
9
  Brotli cache works as a proxy layer wrapping the standard cache data store. It applies Brotli compression instead of the default Gzip before storing cache entries.
@@ -42,6 +42,13 @@ module RailsBrotliCache
42
42
  end
43
43
 
44
44
  def write(name, value, options = nil)
45
+ if value.is_a?(Integer)
46
+ return @core_store.write(
47
+ cache_key(name),
48
+ value
49
+ )
50
+ end
51
+
45
52
  serialized = Marshal.dump(value)
46
53
  options = (options || {}).reverse_merge(compress: true)
47
54
 
@@ -72,6 +79,8 @@ module RailsBrotliCache
72
79
 
73
80
  return nil unless payload.present?
74
81
 
82
+ return payload if payload.is_a?(Integer)
83
+
75
84
  serialized = if payload.start_with?(MARK_BR_COMPRESSED)
76
85
  compressor = compressor_class(options, default: @compressor_class)
77
86
  compressor.inflate(payload.byteslice(1..-1))
@@ -94,6 +103,16 @@ module RailsBrotliCache
94
103
  @core_store.clear
95
104
  end
96
105
 
106
+ def increment(*args)
107
+ args[0] = cache_key(args[0])
108
+ @core_store.increment(*args)
109
+ end
110
+
111
+ def decrement(*args)
112
+ args[0] = cache_key(args[0])
113
+ @core_store.decrement(*args)
114
+ end
115
+
97
116
  def self.supports_cache_versioning?
98
117
  true
99
118
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsBrotliCache
4
- VERSION = "0.3.4"
4
+ VERSION = "0.3.6"
5
5
  end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe RailsBrotliCache do
6
+
7
+ CACHE_STORE_TYPES = [
8
+ [ActiveSupport::Cache::MemoryStore.new, ActiveSupport::Cache::MemoryStore.new],
9
+ [ActiveSupport::Cache::RedisCacheStore.new, ActiveSupport::Cache::RedisCacheStore.new],
10
+ [ActiveSupport::Cache::MemCacheStore.new, ActiveSupport::Cache::MemCacheStore.new],
11
+ [ActiveSupport::Cache::FileStore.new('./tmp'), ActiveSupport::Cache::FileStore.new('./tmp')],
12
+ [ActiveSupport::Cache::NullStore.new, ActiveSupport::Cache::NullStore.new]
13
+ ]
14
+
15
+ CACHE_STORE_TYPES.each do |cache_store_types|
16
+ describe "Brotli cache has the same API as #{cache_store_types[0].class}" do
17
+ subject(:brotli_store) do
18
+ RailsBrotliCache::Store.new(cache_store_types[0])
19
+ end
20
+
21
+ let(:standard_cache) do
22
+ cache_store_types[1]
23
+ end
24
+
25
+ it "compares the same cache stores" do
26
+ expect(standard_cache.class).to eq(brotli_store.core_store.class)
27
+ end
28
+
29
+ it "for #clear" do
30
+ expect(brotli_store.clear.class).to eq(standard_cache.clear.class)
31
+ end
32
+
33
+ it "for #read and #write" do
34
+ int_val = 123
35
+ expect(brotli_store.write("int_val_key", int_val).class).to eq(standard_cache.write("int_val_key", int_val).class)
36
+ expect(brotli_store.read("int_val_key")).to eq(standard_cache.read("int_val_key"))
37
+
38
+ str_val = "str"
39
+ expect(brotli_store.write("str_val_key", int_val).class).to eq(standard_cache.write("str_val_key", int_val).class)
40
+ expect(brotli_store.read("str_val_key")).to eq(standard_cache.read("str_val_key"))
41
+
42
+ complex_val = OpenStruct.new(a: 1, b: 2)
43
+ expect(brotli_store.write("complex_val_key", int_val).class).to eq(standard_cache.write("complex_val_key", int_val).class)
44
+ expect(brotli_store.read("complex_val_key")).to eq(standard_cache.read("complex_val_key"))
45
+ end
46
+
47
+ it "for #increment and #decrement" do
48
+ expect(brotli_store.write("inc_val_key", 1).class).to eq(standard_cache.write("inc_val_key", 1).class)
49
+ expect(brotli_store.increment("inc_val_key").class).to eq(standard_cache.increment("inc_val_key").class)
50
+ expect(brotli_store.read("inc_val_key")).to eq(standard_cache.read("inc_val_key"))
51
+ expect(brotli_store.increment("inc_val_key", 2).class).to eq(standard_cache.increment("inc_val_key", 2).class)
52
+ expect(brotli_store.read("inc_val_key")).to eq(standard_cache.read("inc_val_key"))
53
+ expect(brotli_store.decrement("inc_val_key", 2).class).to eq(standard_cache.decrement("inc_val_key", 2).class)
54
+ expect(brotli_store.read("inc_val_key")).to eq(standard_cache.read("inc_val_key"))
55
+ end
56
+
57
+ it "for #fetch" do
58
+ val = "123"
59
+ expect(brotli_store.fetch("val_key") { val }).to eq(standard_cache.fetch("val_key") { val })
60
+ expect(brotli_store.fetch("val_key", force: true) { val }).to eq(standard_cache.fetch("val_key", force: true) { val })
61
+ expect(brotli_store.fetch("val_key")).to eq(standard_cache.fetch("val_key"))
62
+ end
63
+ end
64
+ end
65
+ end
@@ -40,6 +40,20 @@ describe RailsBrotliCache do
40
40
  end
41
41
  end
42
42
 
43
+ describe "#increment and #decrement" do
44
+ it "works" do
45
+ cache_store.write("integer-key", 0)
46
+ cache_store.increment("integer-key")
47
+ expect(cache_store.read("integer-key")).to eq 1
48
+ cache_store.increment("integer-key", 3)
49
+ expect(cache_store.read("integer-key")).to eq 4
50
+ cache_store.decrement("integer-key", 4)
51
+ expect(cache_store.read("integer-key")).to eq 0
52
+ cache_store.decrement("integer-key")
53
+ expect(cache_store.read("integer-key")).to eq -1
54
+ end
55
+ end
56
+
43
57
  describe "exist?" do
44
58
  it "returns true if cache entry exists" do
45
59
  cache_store.write("test-key", 1234)
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
4
+ version: 0.3.6
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-25 00:00:00.000000000 Z
11
+ date: 2023-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -158,6 +158,7 @@ files:
158
158
  - spec/dummy/public/robots.txt
159
159
  - spec/dummy/vendor/.keep
160
160
  - spec/fixtures/sample.json
161
+ - spec/rails-brotli-cache/compatibility_spec.rb
161
162
  - spec/rails-brotli-cache/rails_store_spec.rb
162
163
  - spec/rails-brotli-cache/redis_spec.rb
163
164
  - spec/rails-brotli-cache/store_spec.rb
@@ -230,6 +231,7 @@ test_files:
230
231
  - spec/dummy/public/robots.txt
231
232
  - spec/dummy/vendor/.keep
232
233
  - spec/fixtures/sample.json
234
+ - spec/rails-brotli-cache/compatibility_spec.rb
233
235
  - spec/rails-brotli-cache/rails_store_spec.rb
234
236
  - spec/rails-brotli-cache/redis_spec.rb
235
237
  - spec/rails-brotli-cache/store_spec.rb