gitlab-client-cache 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e3d1c3a537e0ae3dedbd5ddcc6fe82e377f299cea066b3a6352352bffdde1cdf
4
- data.tar.gz: 993e7b32375edc9e7d5a9ff1e3c291168c5ea4b7e6b5dcd9ff3b56249356643e
3
+ metadata.gz: 91f62e80a4ad2f57008c618ad5db4a37360bc629b712848b1aa48e06e50768f8
4
+ data.tar.gz: 0576a4acb6eab7585a40c0de2e87daedfab90b5c0d28d6f56f8f7c36a00db8c1
5
5
  SHA512:
6
- metadata.gz: 40193ec872a903d7429cf0a22f052a99fe1350cc641ffa585562f452fa706ca5e4d98d53a399c0327449a449b7303c03f50f78eca5376c1a1ef6ef04aed045c6
7
- data.tar.gz: 80be8c83333e8cf09e8b31d4d891e30e9c4d720be8d9010823cd7d3b7e41fc412fc53eef31d49a69ab0f28b80286d30d1deab206d0ee1b4f8894a9afa6b39662
6
+ metadata.gz: e6713806ee592b533315b555017fb1ef8917b46b94425a71565f67f57b8e65f3507867fbcbcd191092161e838ca9f565f51695bb596b1610b1e8911a8db352c0
7
+ data.tar.gz: 24ecd0c31f6f3f4c13769e45efc4d105ad090e4509ed38b66eef2a4ac3be2eb9a2ff2849f50b97d363bcaef372eae7fbcd592a0f423a7fe6ef05922048cdcd2a
@@ -11,22 +11,41 @@ class Gitlab::Client::Cache::Caching
11
11
  @config = config
12
12
  end
13
13
 
14
- def cached(http_path, http_params)
15
- path = path_to(http_path, http_params)
14
+ def cached(*args)
15
+ path = path_to(args)
16
16
 
17
- if path.exist? && path_fresh?(path)
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
- dump(path, yield)
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 path_fresh?(path)
27
- return true unless @config.expires_in
30
+ def determine_expires_in(args)
31
+ expires_in = @config.expires_in
32
+
33
+ if expires_in.is_a?(Array)
34
+ expires_in = \
35
+ expires_in.each do |block|
36
+ result = block.is_a?(Proc) ? block.call(*args) : block
37
+ break result unless result == :default
38
+ end
39
+ expires_in = nil if expires_in.is_a?(Array)
40
+ end
41
+
42
+ expires_in
43
+ end
44
+
45
+ def path_fresh?(path, expires_in)
46
+ return true if expires_in.nil?
28
47
 
29
- path.mtime + @config.expires_in >= Time.now
48
+ path.mtime + expires_in >= Time.now
30
49
  end
31
50
 
32
51
  def load(path)
@@ -41,11 +60,9 @@ class Gitlab::Client::Cache::Caching
41
60
  Object.const_get(klass).inflate(content)
42
61
  end
43
62
 
44
- def dump(path, response)
63
+ def dump(path, content)
45
64
  path.dirname.mkpath
46
- path.write(deflate(Marshal.dump(response)))
47
-
48
- response
65
+ path.write(deflate(Marshal.dump(content)))
49
66
  end
50
67
 
51
68
  def deflate(content)
@@ -60,9 +77,8 @@ class Gitlab::Client::Cache::Caching
60
77
  end
61
78
  end
62
79
 
63
- def path_to(http_path, http_params)
64
- params = clean_params(http_params)
65
- plain = JSON.generate([http_path, params])
80
+ def path_to(args)
81
+ plain = JSON.generate(args)
66
82
  key = Digest::SHA256.hexdigest(plain)
67
83
 
68
84
  parts = [
@@ -74,14 +90,6 @@ class Gitlab::Client::Cache::Caching
74
90
  Pathname.new(parts.join("/"))
75
91
  end
76
92
 
77
- def clean_params(params)
78
- params = params.dup
79
- params.delete(:logger)
80
- params.delete(:log_level)
81
-
82
- params
83
- end
84
-
85
93
  def clean_path(path)
86
94
  CGI.escape(path)
87
95
  .gsub(".", "_")
@@ -2,6 +2,10 @@
2
2
 
3
3
  module Gitlab::Client::Cache::Patch
4
4
  def get(path, params = {})
5
+ params = params.dup
6
+ params.delete(:logger)
7
+ params.delete(:log_level)
8
+
5
9
  Gitlab::Client::Cache::Caching.new(Gitlab::Client::Cache.config).cached(path, params) { super }
6
10
  end
7
11
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GitlabClientCache
4
- VERSION = "0.0.2"
4
+ VERSION = "0.0.4"
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.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Leitzen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-07 00:00:00.000000000 Z
11
+ date: 2023-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gitlab