iknow_cache 1.1.1 → 1.2.0
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 +4 -4
- data/lib/iknow_cache/railtie.rb +14 -0
- data/lib/iknow_cache/version.rb +1 -1
- data/lib/iknow_cache.rb +65 -21
- metadata +20 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2f251be058a4e00de4f8dc19eef0cfe2fd35423fe954d74648a51e45b11ee4c
|
4
|
+
data.tar.gz: 807534bc5abde0fe64d7d8a6a419d71e21695617b01e58b94d5da5dc90a39746
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98c3d4cbb6e4f2dd6d6d0c145c3be61734e562927dca4be79ce2f91226faba0633da677be77459fd7b3c47d5a015808da8ab318fb3182f481e31a43d2b3681ce
|
7
|
+
data.tar.gz: c89989310153a661059cd79c58f337263ac711f65f8dc38cd259e2bd5ed0fae03421d1b5e3539fc6a3995c6bb6a8a91169530d8ab37d1042e7fc02a1dcd57b70
|
data/lib/iknow_cache/version.rb
CHANGED
data/lib/iknow_cache.rb
CHANGED
@@ -1,6 +1,46 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class IknowCache
|
4
|
+
Config = Struct.new(:logger, :cache)
|
5
|
+
|
6
|
+
class ConfigWriter
|
7
|
+
def initialize(config)
|
8
|
+
@config = config
|
9
|
+
end
|
10
|
+
|
11
|
+
def logger(logger)
|
12
|
+
@config.logger = logger
|
13
|
+
end
|
14
|
+
|
15
|
+
def cache(cache)
|
16
|
+
@config.cache = cache
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.configured?
|
21
|
+
! config.nil?
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.configure!(&block)
|
25
|
+
raise ArgumentError.new("Already configured!") if configured?
|
26
|
+
|
27
|
+
config = Config.new
|
28
|
+
ConfigWriter.new(config).instance_eval(&block)
|
29
|
+
@config = config.freeze
|
30
|
+
end
|
31
|
+
|
32
|
+
class << self
|
33
|
+
attr_reader :config
|
34
|
+
|
35
|
+
def logger
|
36
|
+
config.logger
|
37
|
+
end
|
38
|
+
|
39
|
+
def cache
|
40
|
+
config.cache
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
4
44
|
def self.register_group(name, key_name, default_options: nil, static_version: 1)
|
5
45
|
group = CacheGroup.new(nil, name, key_name, default_options, static_version)
|
6
46
|
yield group if block_given?
|
@@ -51,7 +91,7 @@ class IknowCache
|
|
51
91
|
# invalidating all caches in it and its children
|
52
92
|
def invalidate_cache_group(parent_key = nil)
|
53
93
|
parent_path = self.parent_path(parent_key)
|
54
|
-
|
94
|
+
IknowCache.cache.increment(version_path_string(parent_path))
|
55
95
|
end
|
56
96
|
|
57
97
|
# Fetch the path for this cache. We allow the parent_path to be precomputed
|
@@ -78,7 +118,7 @@ class IknowCache
|
|
78
118
|
end
|
79
119
|
|
80
120
|
def version(parent_path)
|
81
|
-
|
121
|
+
IknowCache.cache.fetch(version_path_string(parent_path), raw: true) { 1 }
|
82
122
|
end
|
83
123
|
|
84
124
|
# compute multiple paths at once: returns { key => path }
|
@@ -121,12 +161,12 @@ class IknowCache
|
|
121
161
|
version_paths = version_by_pp.values
|
122
162
|
|
123
163
|
# look up versions in cache
|
124
|
-
versions =
|
164
|
+
versions = IknowCache.cache.read_multi(*version_paths, raw: true)
|
125
165
|
|
126
166
|
version_paths.each do |vp|
|
127
167
|
next if versions.has_key?(vp)
|
128
168
|
|
129
|
-
versions[vp] =
|
169
|
+
versions[vp] = IknowCache.cache.fetch(vp, raw: true) { 1 }
|
130
170
|
end
|
131
171
|
|
132
172
|
# swap in the versions
|
@@ -163,33 +203,33 @@ class IknowCache
|
|
163
203
|
|
164
204
|
def fetch(key, parent_path: nil, **options, &block)
|
165
205
|
p = path(key, parent_path)
|
166
|
-
|
167
|
-
v =
|
168
|
-
|
206
|
+
IknowCache.logger.debug("Cache Fetch: #{p}") if DEBUG
|
207
|
+
v = IknowCache.cache.fetch(p, IknowCache.merge_options(cache_options, options), &block)
|
208
|
+
IknowCache.logger.debug("=> #{v.inspect}") if DEBUG
|
169
209
|
v
|
170
210
|
end
|
171
211
|
|
172
212
|
def read(key, parent_path: nil, **options)
|
173
213
|
p = path(key, parent_path)
|
174
|
-
|
175
|
-
v =
|
176
|
-
|
214
|
+
IknowCache.logger.debug("Cache Read: #{p}") if DEBUG
|
215
|
+
v = IknowCache.cache.read(p, IknowCache.merge_options(cache_options, options))
|
216
|
+
IknowCache.logger.debug("=> #{v.inspect}") if DEBUG
|
177
217
|
v
|
178
218
|
end
|
179
219
|
|
180
220
|
def write(key, value, parent_path: nil, **options)
|
181
221
|
p = path(key, parent_path)
|
182
222
|
if DEBUG
|
183
|
-
|
184
|
-
|
223
|
+
IknowCache.logger.debug("Cache Store: #{p} (#{IknowCache.merge_options(cache_options, options).inspect})")
|
224
|
+
IknowCache.logger.debug("<= #{value.inspect}")
|
185
225
|
end
|
186
|
-
|
226
|
+
IknowCache.cache.write(p, value, IknowCache.merge_options(cache_options, options))
|
187
227
|
end
|
188
228
|
|
189
229
|
def delete(key, parent_path: nil, **options)
|
190
230
|
p = path(key, parent_path)
|
191
|
-
|
192
|
-
|
231
|
+
IknowCache.logger.debug("Cache Delete: #{p}") if DEBUG
|
232
|
+
IknowCache.cache.delete(p, IknowCache.merge_options(cache_options, options))
|
193
233
|
end
|
194
234
|
|
195
235
|
def read_multi(keys)
|
@@ -198,12 +238,12 @@ class IknowCache
|
|
198
238
|
key_paths = path_multi(keys)
|
199
239
|
path_keys = key_paths.invert
|
200
240
|
|
201
|
-
|
202
|
-
raw =
|
241
|
+
IknowCache.logger.debug("Cache Multi-Read: #{key_paths.values.inspect}") if DEBUG
|
242
|
+
raw = IknowCache.cache.read_multi(*key_paths.values)
|
203
243
|
vs = raw.each_with_object({}) do |(path, value), h|
|
204
244
|
h[path_keys[path]] = value
|
205
245
|
end
|
206
|
-
|
246
|
+
IknowCache.logger.debug("=> #{vs.inspect}") if DEBUG
|
207
247
|
vs
|
208
248
|
end
|
209
249
|
|
@@ -214,12 +254,14 @@ class IknowCache
|
|
214
254
|
options = IknowCache.merge_options(cache_options, options)
|
215
255
|
|
216
256
|
entries.each do |key, value|
|
217
|
-
|
218
|
-
|
257
|
+
IknowCache.logger.debug("Cache Multi-Write: #{key_paths[key]}") if DEBUG
|
258
|
+
IknowCache.cache.write(key_paths[key], value, options)
|
219
259
|
end
|
220
260
|
end
|
221
261
|
|
222
|
-
|
262
|
+
def key
|
263
|
+
cache_group.key
|
264
|
+
end
|
223
265
|
|
224
266
|
private
|
225
267
|
|
@@ -249,3 +291,5 @@ class IknowCache
|
|
249
291
|
end
|
250
292
|
end
|
251
293
|
end
|
294
|
+
|
295
|
+
require "iknow_cache/railtie" if defined?(Rails::Railtie)
|
metadata
CHANGED
@@ -1,23 +1,37 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iknow_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Andreae
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: minitest
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
16
30
|
requirements:
|
17
31
|
- - ">"
|
18
32
|
- !ruby/object:Gem::Version
|
19
33
|
version: '5.0'
|
20
|
-
type: :
|
34
|
+
type: :development
|
21
35
|
prerelease: false
|
22
36
|
version_requirements: !ruby/object:Gem::Requirement
|
23
37
|
requirements:
|
@@ -63,6 +77,7 @@ files:
|
|
63
77
|
- README.md
|
64
78
|
- Rakefile
|
65
79
|
- lib/iknow_cache.rb
|
80
|
+
- lib/iknow_cache/railtie.rb
|
66
81
|
- lib/iknow_cache/version.rb
|
67
82
|
homepage: https://github.com/iknow/iknow_cache
|
68
83
|
licenses:
|
@@ -83,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
98
|
- !ruby/object:Gem::Version
|
84
99
|
version: '0'
|
85
100
|
requirements: []
|
86
|
-
rubygems_version: 3.
|
101
|
+
rubygems_version: 3.1.6
|
87
102
|
signing_key:
|
88
103
|
specification_version: 4
|
89
104
|
summary: iKnow's versioned nested cache
|