iknow_cache 1.2.0 → 1.2.1

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: f2f251be058a4e00de4f8dc19eef0cfe2fd35423fe954d74648a51e45b11ee4c
4
- data.tar.gz: 807534bc5abde0fe64d7d8a6a419d71e21695617b01e58b94d5da5dc90a39746
3
+ metadata.gz: b80c0ec650d3fd5801512fefc162526b6502da2553e1640a3495defe4f7c5195
4
+ data.tar.gz: e5aa1520f3ffe851ca6bf37fd71946e44dd9706b1cf38b781c88cdfd11494607
5
5
  SHA512:
6
- metadata.gz: 98c3d4cbb6e4f2dd6d6d0c145c3be61734e562927dca4be79ce2f91226faba0633da677be77459fd7b3c47d5a015808da8ab318fb3182f481e31a43d2b3681ce
7
- data.tar.gz: c89989310153a661059cd79c58f337263ac711f65f8dc38cd259e2bd5ed0fae03421d1b5e3539fc6a3995c6bb6a8a91169530d8ab37d1042e7fc02a1dcd57b70
6
+ metadata.gz: 50155988a7d4926758e063c06d01e0791e646ce0177ee33652384079fb88e403dc62718cc648f14115b8596f776f619f6e64ea64d2b3a9189a67c764720f083a
7
+ data.tar.gz: 8e4464752708f4e966822a08b05c68d514fa31b90ecad296748f2fdacb1e735ab379e2a135b0c7a50f338de88ce2e128c408f17046455a4b1fd565cedcc84ec1
@@ -1,3 +1,3 @@
1
1
  class IknowCache
2
- VERSION = '1.2.0'
2
+ VERSION = '1.2.1'
3
3
  end
data/lib/iknow_cache.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'active_support/version'
4
+
3
5
  class IknowCache
4
6
  Config = Struct.new(:logger, :cache)
5
7
 
@@ -18,11 +20,11 @@ class IknowCache
18
20
  end
19
21
 
20
22
  def self.configured?
21
- ! config.nil?
23
+ !config.nil?
22
24
  end
23
25
 
24
26
  def self.configure!(&block)
25
- raise ArgumentError.new("Already configured!") if configured?
27
+ raise ArgumentError.new('Already configured!') if configured?
26
28
 
27
29
  config = Config.new
28
30
  ConfigWriter.new(config).instance_eval(&block)
@@ -69,8 +71,8 @@ class IknowCache
69
71
  group
70
72
  end
71
73
 
72
- def register_cache(name, cache_options: nil)
73
- c = Cache.new(self, name, cache_options)
74
+ def register_cache(name, static_version: nil, cache_options: nil)
75
+ c = Cache.new(self, name, static_version, cache_options)
74
76
  @caches << c
75
77
  c
76
78
  end
@@ -193,12 +195,13 @@ class IknowCache
193
195
  class Cache
194
196
  DEBUG = false
195
197
 
196
- attr_reader :name, :cache_options, :cache_group
198
+ attr_reader :name, :static_version, :cache_options, :cache_group
197
199
 
198
- def initialize(cache_group, name, cache_options)
199
- @cache_group = cache_group
200
- @name = name
201
- @cache_options = IknowCache.merge_options(cache_group.default_options, cache_options).try { |x| x.dup.freeze }
200
+ def initialize(cache_group, name, static_version, cache_options)
201
+ @cache_group = cache_group
202
+ @name = name
203
+ @static_version = static_version
204
+ @cache_options = IknowCache.merge_options(cache_group.default_options, cache_options).try { |x| x.dup.freeze }
202
205
  end
203
206
 
204
207
  def fetch(key, parent_path: nil, **options, &block)
@@ -232,6 +235,19 @@ class IknowCache
232
235
  IknowCache.cache.delete(p, IknowCache.merge_options(cache_options, options))
233
236
  end
234
237
 
238
+ def fetch_multi(keys, write_options = nil)
239
+ results = read_multi(keys)
240
+
241
+ missing_keys = keys - results.keys
242
+ if missing_keys.present?
243
+ loaded_results = yield(missing_keys)
244
+ write_multi(loaded_results, write_options)
245
+ results.merge!(loaded_results)
246
+ end
247
+
248
+ results
249
+ end
250
+
235
251
  def read_multi(keys)
236
252
  return {} if keys.blank?
237
253
 
@@ -240,9 +256,7 @@ class IknowCache
240
256
 
241
257
  IknowCache.logger.debug("Cache Multi-Read: #{key_paths.values.inspect}") if DEBUG
242
258
  raw = IknowCache.cache.read_multi(*key_paths.values)
243
- vs = raw.each_with_object({}) do |(path, value), h|
244
- h[path_keys[path]] = value
245
- end
259
+ vs = raw.transform_keys { |path| path_keys[path] }
246
260
  IknowCache.logger.debug("=> #{vs.inspect}") if DEBUG
247
261
  vs
248
262
  end
@@ -259,6 +273,23 @@ class IknowCache
259
273
  end
260
274
  end
261
275
 
276
+ if Gem::Version.new(ActiveSupport::VERSION::STRING) >= Gem::Version.new('6.1')
277
+ def delete_multi(keys, **options)
278
+ return if keys.blank?
279
+
280
+ key_paths = path_multi(keys)
281
+
282
+ IknowCache.logger.debug("Cache Delete Multi: #{key_paths}") if DEBUG
283
+ IknowCache.cache.delete_multi(key_paths.values, IknowCache.merge_options(cache_options, options))
284
+ end
285
+ else
286
+ def delete_multi(keys, **options)
287
+ keys.each do |key|
288
+ delete(key, **options)
289
+ end
290
+ end
291
+ end
292
+
262
293
  def key
263
294
  cache_group.key
264
295
  end
@@ -277,7 +308,9 @@ class IknowCache
277
308
  end
278
309
 
279
310
  def path_string(group_path)
280
- "#{group_path}/#{self.name}"
311
+ path = "#{group_path}/#{self.name}"
312
+ path = "#{path}/#{self.static_version}" if static_version
313
+ path
281
314
  end
282
315
  end
283
316
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iknow_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Andreae
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-12 00:00:00.000000000 Z
11
+ date: 2024-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest