singleton-client-test 0.7.0.25 → 0.7.0.26

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/sgtn-client/core/cache.rb +18 -18
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 581b02396037c20da7ab2a9248e8522c60735bd1e6e11dd8d4a15af259737b2c
4
- data.tar.gz: ec310a666d7c5384e552fdaad105d06972fded90df51f0760a4622abc8e39489
3
+ metadata.gz: 6a0d174f65d5ce5b87ead4f4c61bc57070bc051ab51bc65343c7ca50a0fd0b68
4
+ data.tar.gz: eaf356bee612ecf0f512083e029964de5307acd3dc05555c710ce386384346ea
5
5
  SHA512:
6
- metadata.gz: b51088e04941faff963f289b7bbfefcfa9730f78682cb85adca816044dc1432972c3eb1c1f940ac2128b4953397a2ab565a1dbfc0b63fe00f9d79f49b4de7b3a
7
- data.tar.gz: 545e8d51467d99c4ea57eb45d9f23a651997de2b07fe9eb331fd39f7042728fe2d23312ff8b0fda0f83564674aaf3d42fcf921266241913e875bb2371ccd1af6
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
- $opts = opts
8
+ @@opts = opts
9
9
  @mutex = Mutex.new
10
10
  SgtnClient.logger.debug "Initialize cache......"
11
11
  if disabled == false
12
- $data = Hash.new
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 $data == nil
20
+ if @@data == nil
21
21
  return nil
22
22
  end
23
23
  SgtnClient.logger.debug "Get cache keys"
24
- $data.keys
24
+ @@data.keys
25
25
  end
26
26
 
27
27
  def self.get(key)
28
- if $data == nil
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
- $data[key][:value] if has(key)
33
+ @@data[key][:value] if has(key)
34
34
  end
35
35
 
36
36
  def self.has(key)
37
- if $data == nil
37
+ if @@data == nil
38
38
  return nil
39
39
  end
40
40
  SgtnClient.logger.debug "Has cache for key: " + key
41
- $data.has_key? key
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 $data == nil
46
+ if @@data == nil
47
47
  return nil
48
48
  end
49
- ttl ||= @opts[: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
- $data[key] = Entry.new(Time.now + ttl*60, value)
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 $data == nil
58
+ if @@data == nil
59
59
  return nil
60
60
  end
61
61
  SgtnClient.logger.debug "Delete cache for key: " + key
62
- $data.delete key
62
+ @@data.delete key
63
63
  end
64
64
  end
65
65
 
66
66
  def self.clear
67
67
  @mutex.synchronize do
68
- if $data == nil
68
+ if @@data == nil
69
69
  return nil
70
70
  end
71
71
  SgtnClient.logger.debug "Clear cache!"
72
- $data = Hash.new
72
+ @@data = Hash.new
73
73
  end
74
74
  end
75
75
 
76
76
  def self.invalidate
77
77
  @mutex.synchronize do
78
- if $data == nil
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
- $data.each {
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
- $data.delete_if {|k, v| v[:expiry] < now}
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.25
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-18 00:00:00.000000000 Z
11
+ date: 2022-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client