singleton-client-test 0.7.0.25 → 0.7.0.26
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/sgtn-client/core/cache.rb +18 -18
- 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: 6a0d174f65d5ce5b87ead4f4c61bc57070bc051ab51bc65343c7ca50a0fd0b68
|
4
|
+
data.tar.gz: eaf356bee612ecf0f512083e029964de5307acd3dc05555c710ce386384346ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 512573410bae6caa91cf0b893f27e95a0864a0374e75bd601a55a2f471ca75ed69c6f537aeb24ca7b9202a6bc59c231a838c3d5a167fdc56f130c8ab844a32e5
|
7
|
+
data.tar.gz: 6a2f2f82f806b564ede5218c7cda2123e528515f5089bb4ea3658451598174d140006e9d075ed68e4b1ae3c04b78b4dc3892a00bc26e447387edb282a8f35c9b
|
@@ -5,11 +5,11 @@ module SgtnClient::Core
|
|
5
5
|
Entry = Struct.new(:expiry, :value)
|
6
6
|
|
7
7
|
def self.initialize(disabled=false, opts={})
|
8
|
-
|
8
|
+
@@opts = opts
|
9
9
|
@mutex = Mutex.new
|
10
10
|
SgtnClient.logger.debug "Initialize cache......"
|
11
11
|
if disabled == false
|
12
|
-
|
12
|
+
@@data = Hash.new
|
13
13
|
SgtnClient.logger.debug "Cache is enabled!"
|
14
14
|
else
|
15
15
|
SgtnClient.logger.debug "Cache is disabled!"
|
@@ -17,74 +17,74 @@ module SgtnClient::Core
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def self.keys
|
20
|
-
if
|
20
|
+
if @@data == nil
|
21
21
|
return nil
|
22
22
|
end
|
23
23
|
SgtnClient.logger.debug "Get cache keys"
|
24
|
-
|
24
|
+
@@data.keys
|
25
25
|
end
|
26
26
|
|
27
27
|
def self.get(key)
|
28
|
-
if
|
28
|
+
if @@data == nil
|
29
29
|
return nil
|
30
30
|
end
|
31
31
|
SgtnClient.logger.debug "Get cache for key: " + key
|
32
32
|
invalidate
|
33
|
-
|
33
|
+
@@data[key][:value] if has(key)
|
34
34
|
end
|
35
35
|
|
36
36
|
def self.has(key)
|
37
|
-
if
|
37
|
+
if @@data == nil
|
38
38
|
return nil
|
39
39
|
end
|
40
40
|
SgtnClient.logger.debug "Has cache for key: " + key
|
41
|
-
|
41
|
+
@@data.has_key? key
|
42
42
|
end
|
43
43
|
|
44
44
|
def self.put(key, value, ttl=nil)
|
45
45
|
@mutex.synchronize do
|
46
|
-
if
|
46
|
+
if @@data == nil
|
47
47
|
return nil
|
48
48
|
end
|
49
|
-
ttl ||=
|
49
|
+
ttl ||= @@opts[:ttl]
|
50
50
|
# hours from new
|
51
51
|
SgtnClient.logger.debug "Put cache for key '" + key + "' with expired time at'" + (Time.now + ttl*60).to_s
|
52
|
-
|
52
|
+
@@data[key] = Entry.new(Time.now + ttl*60, value)
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
56
|
def self.delete(key)
|
57
57
|
@mutex.synchronize do
|
58
|
-
if
|
58
|
+
if @@data == nil
|
59
59
|
return nil
|
60
60
|
end
|
61
61
|
SgtnClient.logger.debug "Delete cache for key: " + key
|
62
|
-
|
62
|
+
@@data.delete key
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
66
|
def self.clear
|
67
67
|
@mutex.synchronize do
|
68
|
-
if
|
68
|
+
if @@data == nil
|
69
69
|
return nil
|
70
70
|
end
|
71
71
|
SgtnClient.logger.debug "Clear cache!"
|
72
|
-
|
72
|
+
@@data = Hash.new
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
76
|
def self.invalidate
|
77
77
|
@mutex.synchronize do
|
78
|
-
if
|
78
|
+
if @@data == nil
|
79
79
|
return nil
|
80
80
|
end
|
81
81
|
SgtnClient.logger.debug "Invalidating expired cache......"
|
82
82
|
now = Time.now
|
83
|
-
|
83
|
+
@@data.each {
|
84
84
|
|k, v|
|
85
85
|
SgtnClient.logger.debug "Checking cache: key=#{k}, expiredtime=#{v[:expiry]}, now=#{now}, expired=#{(v[:expiry] < now)}"
|
86
86
|
}
|
87
|
-
|
87
|
+
@@data.delete_if {|k, v| v[:expiry] < now}
|
88
88
|
end
|
89
89
|
end
|
90
90
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: singleton-client-test
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.0.
|
4
|
+
version: 0.7.0.26
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- VMware G11n Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-01-
|
11
|
+
date: 2022-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|