rails-brotli-cache 0.3.5 → 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: 0d2a98f625745f1051b66f22f71dfb7c284eec5d8a1087378222bea371543803
4
- data.tar.gz: dbd97601e6ca601ffe088bbeeb2491e00fd8f34c9f363cf263228630f8cdfcc9
3
+ metadata.gz: 2d61874a96a2402ac69abd17762f98531de0a5b2c2749447f3c34d03dc76b57b
4
+ data.tar.gz: dff930d1caf6e592d207db48ffb175ebcd06bc59d228a9b5a78e3185672ee72d
5
5
  SHA512:
6
- metadata.gz: d58c6cdd1fc0c569e7ed2d2c76584a91fcef49be8aaacfa80875b32a7995590fa441a9dfa0fd8a0dbdf554cbe95b5c2bd424358146c311a9d98a11fd3b0a3ad9
7
- data.tar.gz: 308a8e81bd0ed6909b2dd5184a27bdcfcdbad3708e259af0f5a6c13902afb5b98f721341ad8a016d2a9935d6baf0fcb2ff9d14059aef6b5cca44c42487184884
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
 
@@ -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
 
@@ -96,12 +103,14 @@ module RailsBrotliCache
96
103
  @core_store.clear
97
104
  end
98
105
 
99
- def increment(name, amount = 1, options = nil)
100
- @core_store.increment(cache_key(name), amount, options)
106
+ def increment(*args)
107
+ args[0] = cache_key(args[0])
108
+ @core_store.increment(*args)
101
109
  end
102
110
 
103
- def decrement(name, amount = 1, options = nil)
104
- @core_store.decrement(cache_key(name), amount, options)
111
+ def decrement(*args)
112
+ args[0] = cache_key(args[0])
113
+ @core_store.decrement(*args)
105
114
  end
106
115
 
107
116
  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.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
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.3.5
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - pawurb
@@ -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