gitlab-client-cache 0.0.3 → 0.0.5
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/gitlab/client/cache/caching.rb +20 -22
- data/lib/gitlab/client/cache/patch.rb +5 -1
- data/lib/gitlab/client/cache/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2dda76e9f1f1172d8de24dd9bfa27ec091bb26588ea054c17a40f19ae12a3ab2
|
4
|
+
data.tar.gz: fe3fcd64125ecc3f9126b44c77778b94881200350c9fe0cb48cc9a69fb59fbe8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00ab1a36bd9e1c7f0f41b0564fccfebf6a7b586a885d60ad5b764bacad9610a5dab2e79095ae268178b9235778b907790e68b9f1049b8419fceb4043d8999c10
|
7
|
+
data.tar.gz: 41f244bcad85e4bb8f14b84452a5b6128e591a2c21685dce19dbb2e33085ff6ebb6de4134d5dab34d03aadead48106513f1e3980bc93057d3b4a027a824fb1a6
|
@@ -11,30 +11,39 @@ class Gitlab::Client::Cache::Caching
|
|
11
11
|
@config = config
|
12
12
|
end
|
13
13
|
|
14
|
-
def cached(
|
15
|
-
path = path_to(
|
14
|
+
def cached(*args)
|
15
|
+
path = path_to(args)
|
16
16
|
|
17
|
-
|
17
|
+
expires_in = determine_expires_in(args)
|
18
|
+
|
19
|
+
if expires_in != :skip_caching && path.exist? && path_fresh?(path, expires_in)
|
18
20
|
load(path)
|
19
21
|
else
|
20
|
-
|
22
|
+
result = yield
|
23
|
+
dump(path, result) unless expires_in == :skip_caching
|
24
|
+
result
|
21
25
|
end
|
22
26
|
end
|
23
27
|
|
24
28
|
private
|
25
29
|
|
26
|
-
def
|
30
|
+
def determine_expires_in(args)
|
27
31
|
expires_in = @config.expires_in
|
28
32
|
|
29
33
|
if expires_in.is_a?(Array)
|
30
34
|
expires_in = \
|
31
35
|
expires_in.each do |block|
|
32
|
-
result = block.is_a?(Proc) ? block.call(
|
36
|
+
result = block.is_a?(Proc) ? block.call(*args) : block
|
33
37
|
break result unless result == :default
|
34
38
|
end
|
39
|
+
expires_in = nil if expires_in.is_a?(Array)
|
35
40
|
end
|
36
41
|
|
37
|
-
|
42
|
+
expires_in
|
43
|
+
end
|
44
|
+
|
45
|
+
def path_fresh?(path, expires_in)
|
46
|
+
return true if expires_in.nil?
|
38
47
|
|
39
48
|
path.mtime + expires_in >= Time.now
|
40
49
|
end
|
@@ -51,11 +60,9 @@ class Gitlab::Client::Cache::Caching
|
|
51
60
|
Object.const_get(klass).inflate(content)
|
52
61
|
end
|
53
62
|
|
54
|
-
def dump(path,
|
63
|
+
def dump(path, content)
|
55
64
|
path.dirname.mkpath
|
56
|
-
path.write(deflate(Marshal.dump(
|
57
|
-
|
58
|
-
response
|
65
|
+
path.write(deflate(Marshal.dump(content)))
|
59
66
|
end
|
60
67
|
|
61
68
|
def deflate(content)
|
@@ -70,9 +77,8 @@ class Gitlab::Client::Cache::Caching
|
|
70
77
|
end
|
71
78
|
end
|
72
79
|
|
73
|
-
def path_to(
|
74
|
-
|
75
|
-
plain = JSON.generate([http_path, params])
|
80
|
+
def path_to(args)
|
81
|
+
plain = JSON.generate(args)
|
76
82
|
key = Digest::SHA256.hexdigest(plain)
|
77
83
|
|
78
84
|
parts = [
|
@@ -84,14 +90,6 @@ class Gitlab::Client::Cache::Caching
|
|
84
90
|
Pathname.new(parts.join("/"))
|
85
91
|
end
|
86
92
|
|
87
|
-
def clean_params(params)
|
88
|
-
params = params.dup
|
89
|
-
params.delete(:logger)
|
90
|
-
params.delete(:log_level)
|
91
|
-
|
92
|
-
params
|
93
|
-
end
|
94
|
-
|
95
93
|
def clean_path(path)
|
96
94
|
CGI.escape(path)
|
97
95
|
.gsub(".", "_")
|
@@ -2,7 +2,11 @@
|
|
2
2
|
|
3
3
|
module Gitlab::Client::Cache::Patch
|
4
4
|
def get(path, params = {})
|
5
|
-
|
5
|
+
params_for_path = params.dup
|
6
|
+
params_for_path.delete(:logger)
|
7
|
+
params_for_path.delete(:log_level)
|
8
|
+
|
9
|
+
Gitlab::Client::Cache::Caching.new(Gitlab::Client::Cache.config).cached(path, params_for_path) { super }
|
6
10
|
end
|
7
11
|
end
|
8
12
|
|
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.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Leitzen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gitlab
|