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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8331d649faef4d9b5ba700f8ac93cad2a263bd293e5535c721ed57a170140c7f
4
- data.tar.gz: a26ffaba10d13a680e611aa39ba5d3b217acb4c786269b7435d05a354e4ae00c
3
+ metadata.gz: fc2112aca3d10eefa5cbdc4996ee4e31fba80c16fd9900e2f8db7b63fb45039e
4
+ data.tar.gz: d1fa15f13c2d8eceaa5a197dd3adb7890c2279a52855f9ded03deaf73ddbc784
5
5
  SHA512:
6
- metadata.gz: c4a5cfdda959a00ea4e79bc41b296771f2eb44cb0dbae1db5f1daf638a6995b7f19b1f678cdfa64139424cd9cf639e92130dbfc1e8fb35f38f5cf2f31331861b
7
- data.tar.gz: 9228a6f6c205dfaca58386cf08777818a8e57ceb48726dcb705625dec76cabcb3aa9d2da43bd7645bd6cb06b7782e24c484432bb1a550033c165e028afb44276
6
+ metadata.gz: a51b76cd9d1903797d3dec529631c25ef8d1d3e326d3a73a86f76a1ac238902e679d9bda5809e701f9b5cad1a31b8f87ac6c5b54d957a2b78162fd4b184f5cf6
7
+ data.tar.gz: 95dc3cb99f04834cb29c86515e2ab8d6a0e1c73d572e23b28b043a060f3c98f356a8f57d7314451672483482ccbdd67195c85c253233b1488a004539ee3c67c9
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-2.5.0
1
+ ruby-3.0.2
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "http://rubygems.org"
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in coffee_table.gemspec
4
4
  gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- coffee_table (0.3.0)
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: http://rubygems.org/
12
+ remote: https://rubygems.org/
13
13
  specs:
14
- activesupport (6.0.3.1)
14
+ activesupport (6.1.3.1)
15
15
  concurrent-ruby (~> 1.0, >= 1.0.2)
16
- i18n (>= 0.7, < 2)
17
- minitest (~> 5.1)
18
- tzinfo (~> 1.1)
19
- zeitwerk (~> 2.2, >= 2.2.2)
20
- concurrent-ruby (1.1.6)
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.3)
32
+ i18n (1.8.10)
33
33
  concurrent-ruby (~> 1.0)
34
34
  json (2.3.0)
35
- minitest (5.14.1)
35
+ minitest (5.14.4)
36
36
  mock_redis (0.23.0)
37
- redis (4.2.1)
38
- redis-namespace (1.7.0)
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.14.2)
58
+ ruby_parser (3.15.1)
59
59
  sexp_processor (~> 4.9)
60
- sexp_processor (4.15.0)
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 (1.2.7)
80
- thread_safe (~> 0.1)
81
- zeitwerk (2.3.0)
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
@@ -1,3 +1,3 @@
1
1
  module CoffeeTable
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.1"
3
3
  end
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
- @redis.get("test_key|90a52c9dc8646bf66e93ce76578306c6|compressed=true").should start_with "\u0004"
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|0402899032596ee850d5271ab2312906|")).should eql "BAh7BjoJdGVzdEkiNnRoaXMgdmFsdWUgaXMgYSBkZWNlbnQgbGVuZ3RoIHRv\nIHRyaWdnZXIgY29tcHJlc3MGOgZFVA==\n"
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|90a52c9dc8646bf66e93ce76578306c6|").should eql Marshal.dump("this string should be long")
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|55d2ae66967c26b2fef23e5ed6bd3930|").should eql Marshal.dump("short")
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.3.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: 2020-06-12 00:00:00.000000000 Z
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
- rubyforge_project: coffee_table
203
- rubygems_version: 2.7.8
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: