rails-brotli-cache 0.3.5 → 0.3.7

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: 0d2a98f625745f1051b66f22f71dfb7c284eec5d8a1087378222bea371543803
4
- data.tar.gz: dbd97601e6ca601ffe088bbeeb2491e00fd8f34c9f363cf263228630f8cdfcc9
3
+ metadata.gz: 80eea251ed8707e59e4f8a9b829c7046dd9343edcd045e4ef83aa840d8fc5fae
4
+ data.tar.gz: fbe018c38651848f9aba05d3b59e96c802b7afddc36099cc8d5a5a1099fd3975
5
5
  SHA512:
6
- metadata.gz: d58c6cdd1fc0c569e7ed2d2c76584a91fcef49be8aaacfa80875b32a7995590fa441a9dfa0fd8a0dbdf554cbe95b5c2bd424358146c311a9d98a11fd3b0a3ad9
7
- data.tar.gz: 308a8e81bd0ed6909b2dd5184a27bdcfcdbad3708e259af0f5a6c13902afb5b98f721341ad8a016d2a9935d6baf0fcb2ff9d14059aef6b5cca44c42487184884
6
+ metadata.gz: c4b1622f27a59b6b46067a5ee1d354a0696029e6ebdd71b8be913c59f021251a9862600b08ed12fb7111c7a9183bc07903227a3dc0f3d9ee1563e60de0546dc8
7
+ data.tar.gz: 80a043902519762f273c65ce864ed0c9e64397c72a3a750f513e335502b46e7c1876a8d28653147db01b4762ba28be3c8f2dd4657e06671d140959a4aa0f3c09
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
 
@@ -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
 
@@ -84,7 +91,29 @@ module RailsBrotliCache
84
91
  Marshal.load(serialized)
85
92
  end
86
93
 
87
- def exist?(name, options = nil)
94
+ def write_multi(hash, options = nil)
95
+ hash.each do |key, val|
96
+ write(key, val, options)
97
+ end
98
+ end
99
+
100
+ def read_multi(*names)
101
+ options = names.extract_options!
102
+
103
+ Hash[names.map do |name|
104
+ [name, read(name, options)]
105
+ end]
106
+ end
107
+
108
+ def fetch_multi(*names)
109
+ options = names.extract_options!
110
+
111
+ names.each do |name|
112
+ fetch(name, options) { yield(name) }
113
+ end
114
+ end
115
+
116
+ def exist?(name, options = nil)
88
117
  @core_store.exist?(cache_key(name), options)
89
118
  end
90
119
 
@@ -96,12 +125,14 @@ module RailsBrotliCache
96
125
  @core_store.clear
97
126
  end
98
127
 
99
- def increment(name, amount = 1, options = nil)
100
- @core_store.increment(cache_key(name), amount, options)
128
+ def increment(*args)
129
+ args[0] = cache_key(args[0])
130
+ @core_store.increment(*args)
101
131
  end
102
132
 
103
- def decrement(name, amount = 1, options = nil)
104
- @core_store.decrement(cache_key(name), amount, options)
133
+ def decrement(*args)
134
+ args[0] = cache_key(args[0])
135
+ @core_store.decrement(*args)
105
136
  end
106
137
 
107
138
  def self.supports_cache_versioning?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsBrotliCache
4
- VERSION = "0.3.5"
4
+ VERSION = "0.3.7"
5
5
  end
@@ -0,0 +1,105 @@
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
+
64
+ it "for #write_multi and #read_multi" do
65
+ if standard_cache.class != ActiveSupport::Cache::NullStore ## NullStore does not support read/write multi
66
+ values = {
67
+ "key_1" => "val_1",
68
+ "key_2" => "val_2"
69
+ }
70
+
71
+ brotli_store.write_multi(values)
72
+ standard_cache.write_multi(values)
73
+ expect(brotli_store.read("key_1")).to eq "val_1"
74
+ expect(brotli_store.read("key_2")).to eq "val_2"
75
+ expect(standard_cache.read("key_1")).to eq "val_1"
76
+ expect(standard_cache.read("key_2")).to eq "val_2"
77
+
78
+ expect(brotli_store.read_multi("key_1", "key_2")).to eq(standard_cache.read_multi("key_1", "key_2"))
79
+ end
80
+ end
81
+
82
+ it "for #fetch_multi" do
83
+ if standard_cache.class != ActiveSupport::Cache::NullStore ## NullStore does not support fetch multi
84
+ values = {
85
+ "key_1" => "val_1",
86
+ "key_2" => "val_2"
87
+ }
88
+
89
+ brotli_store.fetch_multi("key_1", "key_2") do |key|
90
+ "val_#{key.split('_').last}"
91
+ end
92
+
93
+ standard_cache.fetch_multi("key_1", "key_2") do |key|
94
+ "val_#{key.split('_').last}"
95
+ end
96
+
97
+ expect(brotli_store.read("key_1")).to eq "val_1"
98
+ expect(brotli_store.read("key_2")).to eq "val_2"
99
+
100
+ expect(brotli_store.read_multi("key_1", "key_2")).to eq(standard_cache.read_multi("key_1", "key_2"))
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
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.5
4
+ version: 0.3.7
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-26 00:00:00.000000000 Z
11
+ date: 2023-05-27 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