coffee_table 0.3.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/Gemfile +1 -1
- data/Gemfile.lock +17 -18
- data/README.textile +2 -0
- data/lib/coffee_table/version.rb +1 -1
- data/lib/coffee_table.rb +2 -2
- data/spec/lib/coffee_table_spec.rb +24 -4
- metadata +6 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc2112aca3d10eefa5cbdc4996ee4e31fba80c16fd9900e2f8db7b63fb45039e
|
4
|
+
data.tar.gz: d1fa15f13c2d8eceaa5a197dd3adb7890c2279a52855f9ded03deaf73ddbc784
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a51b76cd9d1903797d3dec529631c25ef8d1d3e326d3a73a86f76a1ac238902e679d9bda5809e701f9b5cad1a31b8f87ac6c5b54d957a2b78162fd4b184f5cf6
|
7
|
+
data.tar.gz: 95dc3cb99f04834cb29c86515e2ab8d6a0e1c73d572e23b28b043a060f3c98f356a8f57d7314451672483482ccbdd67195c85c253233b1488a004539ee3c67c9
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-
|
1
|
+
ruby-3.0.2
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
coffee_table (0.3.
|
4
|
+
coffee_table (0.3.1)
|
5
5
|
activesupport
|
6
6
|
gzip
|
7
7
|
redis
|
@@ -9,15 +9,15 @@ PATH
|
|
9
9
|
sourcify
|
10
10
|
|
11
11
|
GEM
|
12
|
-
remote:
|
12
|
+
remote: https://rubygems.org/
|
13
13
|
specs:
|
14
|
-
activesupport (6.
|
14
|
+
activesupport (6.1.3.1)
|
15
15
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
16
|
-
i18n (>=
|
17
|
-
minitest (
|
18
|
-
tzinfo (~>
|
19
|
-
zeitwerk (~> 2.
|
20
|
-
concurrent-ruby (1.1.
|
16
|
+
i18n (>= 1.6, < 2)
|
17
|
+
minitest (>= 5.1)
|
18
|
+
tzinfo (~> 2.0)
|
19
|
+
zeitwerk (~> 2.3)
|
20
|
+
concurrent-ruby (1.1.8)
|
21
21
|
coveralls (0.8.23)
|
22
22
|
json (>= 1.8, < 3)
|
23
23
|
simplecov (~> 0.16.1)
|
@@ -29,13 +29,13 @@ GEM
|
|
29
29
|
file-tail (1.2.0)
|
30
30
|
tins (~> 1.0)
|
31
31
|
gzip (1.0)
|
32
|
-
i18n (1.8.
|
32
|
+
i18n (1.8.10)
|
33
33
|
concurrent-ruby (~> 1.0)
|
34
34
|
json (2.3.0)
|
35
|
-
minitest (5.14.
|
35
|
+
minitest (5.14.4)
|
36
36
|
mock_redis (0.23.0)
|
37
|
-
redis (4.2.
|
38
|
-
redis-namespace (1.
|
37
|
+
redis (4.2.5)
|
38
|
+
redis-namespace (1.8.1)
|
39
39
|
redis (>= 3.0.4)
|
40
40
|
rspec (3.9.0)
|
41
41
|
rspec-core (~> 3.9.0)
|
@@ -55,9 +55,9 @@ GEM
|
|
55
55
|
ruby2ruby (2.4.4)
|
56
56
|
ruby_parser (~> 3.1)
|
57
57
|
sexp_processor (~> 4.6)
|
58
|
-
ruby_parser (3.
|
58
|
+
ruby_parser (3.15.1)
|
59
59
|
sexp_processor (~> 4.9)
|
60
|
-
sexp_processor (4.15.
|
60
|
+
sexp_processor (4.15.2)
|
61
61
|
simplecov (0.16.1)
|
62
62
|
docile (~> 1.1)
|
63
63
|
json (>= 1.8, < 3)
|
@@ -73,12 +73,11 @@ GEM
|
|
73
73
|
term-ansicolor (1.7.1)
|
74
74
|
tins (~> 1.0)
|
75
75
|
thor (1.0.1)
|
76
|
-
thread_safe (0.3.6)
|
77
76
|
tins (1.25.0)
|
78
77
|
sync
|
79
|
-
tzinfo (
|
80
|
-
|
81
|
-
zeitwerk (2.
|
78
|
+
tzinfo (2.0.4)
|
79
|
+
concurrent-ruby (~> 1.0)
|
80
|
+
zeitwerk (2.4.2)
|
82
81
|
|
83
82
|
PLATFORMS
|
84
83
|
ruby
|
data/README.textile
CHANGED
@@ -49,6 +49,8 @@ end
|
|
49
49
|
|
50
50
|
Each time this is ran when a cache item doesn't exist, a unique cache key is generated based on the data passed in, and the code block being executed. It is good practice to put in objects that are used within the block, as in order to expire the key you need to specify the objects you want to expire for. If this key contained one of those objects, it would be removed and the next time this was ran, fresh data would be placed in the cache.
|
51
51
|
|
52
|
+
You can force to store a new cache entry by passing :force => true
|
53
|
+
|
52
54
|
If you wish to specify a whole model type, for example, all users from above, you would pass in the class, for example:
|
53
55
|
|
54
56
|
bc. user_details = @coffee_table.fetch(:user_detail, User) do
|
data/lib/coffee_table/version.rb
CHANGED
data/lib/coffee_table.rb
CHANGED
@@ -77,11 +77,11 @@ module CoffeeTable
|
|
77
77
|
else
|
78
78
|
expiry = nil
|
79
79
|
end
|
80
|
-
if keys.include?(key.to_s)
|
80
|
+
if keys.include?(key.to_s) && !options[:force]
|
81
81
|
result = marshal_value(@redis.get(key.to_s))
|
82
82
|
else
|
83
83
|
key.add_flag(:compressed => true)
|
84
|
-
if keys.include?(key.to_s)
|
84
|
+
if keys.include?(key.to_s) && !options[:force]
|
85
85
|
result = marshal_value(@redis.get(key.to_s)).gunzip
|
86
86
|
else
|
87
87
|
key.remove_flag(:compressed)
|
@@ -60,7 +60,8 @@ describe CoffeeTable::Cache do
|
|
60
60
|
"this string should be long"
|
61
61
|
end
|
62
62
|
expect(result).to eql "this string should be long"
|
63
|
-
|
63
|
+
puts "asdf"
|
64
|
+
@redis.get("test_key|009e2965832e67d06fb9a1b667cc1aca|compressed=true").should start_with "\u0004"
|
64
65
|
end
|
65
66
|
it "does not compress on non strings" do
|
66
67
|
@coffee_table = CoffeeTable::Cache.new(:server => "127.0.0.1", :port => 6379, :compress_min_size => 20)
|
@@ -68,7 +69,7 @@ describe CoffeeTable::Cache do
|
|
68
69
|
{:test => "this value is a decent length to trigger compress"}
|
69
70
|
end
|
70
71
|
expect(result).to eql ({:test => "this value is a decent length to trigger compress"})
|
71
|
-
Base64.encode64(@redis.get("test_key|
|
72
|
+
Base64.encode64(@redis.get("test_key|8c3fde43e56b71d90843b9555673e120|")).should eql "BAh7BjoJdGVzdEkiNnRoaXMgdmFsdWUgaXMgYSBkZWNlbnQgbGVuZ3RoIHRv\nIHRyaWdnZXIgY29tcHJlc3MGOgZFVA==\n"
|
72
73
|
end
|
73
74
|
|
74
75
|
it "does not compress when turned off" do
|
@@ -77,7 +78,7 @@ describe CoffeeTable::Cache do
|
|
77
78
|
"this string should be long"
|
78
79
|
end
|
79
80
|
expect(result).to eql "this string should be long"
|
80
|
-
@redis.get("test_key|
|
81
|
+
@redis.get("test_key|009e2965832e67d06fb9a1b667cc1aca|").should eql Marshal.dump("this string should be long")
|
81
82
|
end
|
82
83
|
it "does not compress on strings below limit" do
|
83
84
|
@coffee_table = CoffeeTable::Cache.new(:server => "127.0.0.1", :port => 6379, :compress_min_size => 20)
|
@@ -85,7 +86,7 @@ describe CoffeeTable::Cache do
|
|
85
86
|
"short"
|
86
87
|
end
|
87
88
|
expect(result).to eql "short"
|
88
|
-
@redis.get("test_key|
|
89
|
+
@redis.get("test_key|a2e7e06547b31ddc5dff0eba32b64753|").should eql Marshal.dump("short")
|
89
90
|
end
|
90
91
|
it "decompresses compressed value" do
|
91
92
|
@coffee_table = CoffeeTable::Cache.new(:redis => @redis, :compress_min_size => 20)
|
@@ -225,6 +226,25 @@ describe CoffeeTable::Cache do
|
|
225
226
|
expect(result).to eq "this is a changed value"
|
226
227
|
end
|
227
228
|
end
|
229
|
+
context "with force" do
|
230
|
+
it "keys should update when cache expires" do
|
231
|
+
@coffee_table.fetch(:test_key, :force => true) do
|
232
|
+
"object1"
|
233
|
+
end
|
234
|
+
expect(@coffee_table.keys.count).to eq 1
|
235
|
+
end
|
236
|
+
it "should not execute block during cache period" do
|
237
|
+
value = 'this is a value'
|
238
|
+
@coffee_table.fetch("asdf") do
|
239
|
+
value
|
240
|
+
end
|
241
|
+
value = 'this is a changed value'
|
242
|
+
result = @coffee_table.fetch("asdf", :force => true) do
|
243
|
+
value
|
244
|
+
end
|
245
|
+
expect(result).to eq "this is a changed value"
|
246
|
+
end
|
247
|
+
end
|
228
248
|
|
229
249
|
context "changing block" do
|
230
250
|
it "should not change key with same code" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coffee_table
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stewart McKee
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -184,7 +184,7 @@ files:
|
|
184
184
|
homepage: ''
|
185
185
|
licenses: []
|
186
186
|
metadata: {}
|
187
|
-
post_install_message:
|
187
|
+
post_install_message:
|
188
188
|
rdoc_options: []
|
189
189
|
require_paths:
|
190
190
|
- lib
|
@@ -199,9 +199,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
199
199
|
- !ruby/object:Gem::Version
|
200
200
|
version: '0'
|
201
201
|
requirements: []
|
202
|
-
|
203
|
-
|
204
|
-
signing_key:
|
202
|
+
rubygems_version: 3.2.22
|
203
|
+
signing_key:
|
205
204
|
specification_version: 4
|
206
205
|
summary: Gem to manage cache stored in redis
|
207
206
|
test_files:
|