cache_json 1.2.3 → 1.2.4

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: d97faf1cadc565cb04a69dee9bd89df23574d72e9b8b412c2e55dffe201d88db
4
- data.tar.gz: 69e444bf0badc19dc320d644ca4929712d23552537d6493845aab0cb682dff59
3
+ metadata.gz: 5a2871967748d37f7dcca4cc282329618481c1a94e927a91d0edef8dd261e787
4
+ data.tar.gz: 7bf987cd4de3a9a6067ba22e138fec40dd445fa84fbc3770cb78ccb14f409a5b
5
5
  SHA512:
6
- metadata.gz: 2eaae958e037c974bcc9b7042d35b75165c331976989dad8837aee846e60d176a81c4595971f174e5ba25d78f8af9c5fd2035743e0f2ebbbe49118cfbd741e8d
7
- data.tar.gz: b6cd26c9c6e4318844be79eb4193af22318feabed40054e5d0b4b28c2cf705d3abd6c32927f5e6b4853eda4838c16ff07a6377b90ffbfd005eef94f378e0858f
6
+ metadata.gz: 55429caa296c0ff0e0ec826a1de86be8cbad241f4957a1bb7d90498c36dfa3e8cb8a215725271a3c540bcf3e8a87b26198d3460697d1c24015ddc7f89989948d
7
+ data.tar.gz: 7fa105bcbffc4400dbd949b8c64b0b885b868d0e031a2d4047dc33ec8060ec7b40459a55879c6475581836d35ec5d198adc4f8e6e676077d8b97507cc6680e6f
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cache_json (1.2.3)
4
+ cache_json (1.2.4)
5
5
  redis (>= 3.3.5, < 5)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -67,6 +67,7 @@ class ExpensiveJob
67
67
  cache_json_options(
68
68
  time_to_expire: 1.hour,
69
69
  refresh: {
70
+ buffer: 5.minutes,
70
71
  arguments: {
71
72
  first: (5..10),
72
73
  second: ['one option', 'another option'],
@@ -89,7 +90,7 @@ cache_json_worker:
89
90
  class: CacheJSON::Worker
90
91
  ```
91
92
 
92
- Whenever the worker runs, it checks which results have expired, and refreshes only those.
93
+ Whenever the worker runs, it checks which results have expired, and refreshes only those. If you pass in the `buffer` option, it will actually refresh keys that are that far away from expiring. In the example above, the worker will refresh the cache 5 minutes before it expires. This is good if you want to avoid cache misses altogether.
93
94
 
94
95
  ## Development
95
96
 
@@ -31,6 +31,10 @@ module CacheJSON
31
31
  $redis.del(class_key)
32
32
  end
33
33
 
34
+ def cache_expiring_soon?
35
+ $redis.ttl(full_key) < options[:refresh][:buffer].to_i
36
+ end
37
+
34
38
  private
35
39
 
36
40
  def full_key
@@ -17,6 +17,11 @@ module CacheJSON
17
17
  JSON.parse(refresh_cache!(args: args, cache: cache).to_json) # stringify keys
18
18
  end
19
19
 
20
+ def cache_expiring_soon?(args:, cache: nil)
21
+ cache ||= Cache.new(args: args, options: self.class.cache_json_full_options)
22
+ cache.cache_expiring_soon?
23
+ end
24
+
20
25
  def clear_cache!
21
26
  Cache.new(options: self.class.cache_json_full_options).clear_cache!
22
27
  end
@@ -54,6 +59,10 @@ module CacheJSON
54
59
  adapter.clear_cache!
55
60
  end
56
61
 
62
+ def cache_expiring_soon?
63
+ adapter.cache_expiring_soon?
64
+ end
65
+
57
66
  def adapter
58
67
  @adapter ||= CacheJSON::Adapters::Redis.new(args: args, options: options)
59
68
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CacheJSON
4
- VERSION = '1.2.3'
4
+ VERSION = '1.2.4'
5
5
  end
@@ -33,7 +33,7 @@ module CacheJSON
33
33
  private
34
34
 
35
35
  def should_refresh?(klass, args)
36
- !klass.new.check_cache(args: args)
36
+ !klass.new.check_cache(args: args) || klass.new.cache_expiring_soon?(args: args)
37
37
  end
38
38
 
39
39
  class AllPermutations
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cache_json
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Gut
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-29 00:00:00.000000000 Z
11
+ date: 2020-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis