gitlab-client-cache 0.0.5 → 0.0.7

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: 2dda76e9f1f1172d8de24dd9bfa27ec091bb26588ea054c17a40f19ae12a3ab2
4
- data.tar.gz: fe3fcd64125ecc3f9126b44c77778b94881200350c9fe0cb48cc9a69fb59fbe8
3
+ metadata.gz: 999178d96e82fa7361f4b53ac02ea117a76f0e715f86fc2304079459982d5fbc
4
+ data.tar.gz: 0b46a658ecd634397f139cb9bf8f03796622c7a359f53d3913b0750d38372a61
5
5
  SHA512:
6
- metadata.gz: 00ab1a36bd9e1c7f0f41b0564fccfebf6a7b586a885d60ad5b764bacad9610a5dab2e79095ae268178b9235778b907790e68b9f1049b8419fceb4043d8999c10
7
- data.tar.gz: 41f244bcad85e4bb8f14b84452a5b6128e591a2c21685dce19dbb2e33085ff6ebb6de4134d5dab34d03aadead48106513f1e3980bc93057d3b4a027a824fb1a6
6
+ metadata.gz: b2353df47081425afa586134a46f2c43be5ee621ec4e21409cac10f40b7e82ec565cbde24b84ed0f1e18d329909fc2475e69160979d707aa7681054adfe15bdf
7
+ data.tar.gz: 0614f2fc366d1136e282782aaae0cf849584682e988cb4b09792ba9c69f39f5be58e425cfebb4bcdd0bdde52e041fa4554eec7ac8ec2339d47be31add073b2c0
@@ -16,12 +16,14 @@ class Gitlab::Client::Cache::Caching
16
16
 
17
17
  expires_in = determine_expires_in(args)
18
18
 
19
- if expires_in != :skip_caching && path.exist? && path_fresh?(path, expires_in)
19
+ return yield if expires_in == :skip_caching
20
+
21
+ if path.exist? && path_fresh?(path, expires_in)
20
22
  load(path)
21
23
  else
22
- result = yield
23
- dump(path, result) unless expires_in == :skip_caching
24
- result
24
+ value = yield
25
+ dump(path, value)
26
+ value
25
27
  end
26
28
  end
27
29
 
@@ -49,7 +51,9 @@ class Gitlab::Client::Cache::Caching
49
51
  end
50
52
 
51
53
  def load(path)
52
- Marshal.load(inflate(path.read))
54
+ result = Marshal.load(inflate(path.read))
55
+ @config.after_load&.call(result)
56
+ result
53
57
  end
54
58
 
55
59
  def inflate(content)
@@ -60,9 +64,12 @@ class Gitlab::Client::Cache::Caching
60
64
  Object.const_get(klass).inflate(content)
61
65
  end
62
66
 
63
- def dump(path, content)
67
+ def dump(path, value)
68
+ result = @config.before_dump&.call(value)
69
+ return if result == :skip_caching
70
+
64
71
  path.dirname.mkpath
65
- path.write(deflate(Marshal.dump(content)))
72
+ path.write(deflate(Marshal.dump(value)))
66
73
  end
67
74
 
68
75
  def deflate(content)
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gitlab::Client::Cache
4
- Config = Struct.new(:cache_root, :scope, :compression, :expires_in, keyword_init: true) do
4
+ Config = Struct.new(:cache_root, :scope, :compression, :expires_in, :before_dump, :after_load, keyword_init: true) do
5
5
  def self.build
6
6
  new(
7
7
  cache_root: default_cache_root,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GitlabClientCache
4
- VERSION = "0.0.5"
4
+ VERSION = "0.0.7"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab-client-cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Leitzen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-08 00:00:00.000000000 Z
11
+ date: 2024-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gitlab
@@ -59,7 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
59
  - !ruby/object:Gem::Version
60
60
  version: '0'
61
61
  requirements: []
62
- rubygems_version: 3.4.22
62
+ rubygems_version: 3.4.19
63
63
  signing_key:
64
64
  specification_version: 4
65
65
  summary: Response cache for `gitlab` gem