singleton-client-test 0.7.0.27 → 0.7.0.28

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: '0989ae16ca4fcfd6088931a367ac5eb671fd8e087a8d9e32539a2480d1107b34'
4
- data.tar.gz: d750961a5b1c116914f50a947626e0fc4e8a391b3fa28b8e2a77e3651c823ba2
3
+ metadata.gz: d56e992042fd4e5633b41c3de989fd805a44978c696dd7b9692da4191e22b4d4
4
+ data.tar.gz: 99bcb2f0d4e6e502f88c90a5ae27a12349e2af35ff8a2356d781e97e57b8af74
5
5
  SHA512:
6
- metadata.gz: 89e893c6f79dde564732300a4431581effb0dc6aeb7eb3f8fc665c8108d4eaf0292a64e962da259f931c9ebf21299ae05d0db4cac427ec78c5a50c3c81d9a562
7
- data.tar.gz: fd50009cbda5e06c8e1a3d7f81ec02c6b1d060fec95d6824b8e8713f33c48acad660be1e276ee565403cc8eda5abcf9d8f6f0faa936b895ceb9cef29feec0dbd
6
+ metadata.gz: 8f84668bb050779955dbafbb37dd5e2e41a4d793c18552f3c1a51725e906db03e7a13f098329d36596f71adebedf90159d5cc0a85344f8f0bd3c1bd46ca555c9
7
+ data.tar.gz: 4e5f2b2a430b96ca92bd67c9381bfd043f8808a800da6950e5f2e855f860560e96e43ea6f80ef0f9651138026cda0cf7f6ae1f1b84a77b4ea1d0d5de05c0215d
@@ -7,7 +7,7 @@ module SgtnClient
7
7
 
8
8
  def self.getSource(component, key, locale)
9
9
  cache_key = SgtnClient::CacheUtil.get_cachekey(component, locale)
10
- items = SgtnClient::CacheUtil.get_cache(cache_key)
10
+ expired, items = SgtnClient::CacheUtil.get_cache(cache_key)
11
11
  if items.nil?
12
12
  items = getBundle(component, locale)
13
13
  SgtnClient.logger.debug "Putting sources items into cache with key: " + cache_key
@@ -15,7 +15,7 @@ module SgtnClient
15
15
  else
16
16
  SgtnClient.logger.debug "Getting sources from cache with key: " + cache_key
17
17
  end
18
- s = items[locale][key]
18
+ s = items.nil?? nil : items[locale][key]
19
19
  if items.nil? || s.nil?
20
20
  SgtnClient.logger.debug "Source not found, return key: " + key
21
21
  #return key
@@ -27,8 +27,8 @@ module SgtnClient
27
27
 
28
28
  def self.getSources(component, locale)
29
29
  cache_key = SgtnClient::CacheUtil.get_cachekey(component, locale)
30
- items = SgtnClient::CacheUtil.get_cache(cache_key)
31
- if items.nil?
30
+ expired, items = SgtnClient::CacheUtil.get_cache(cache_key)
31
+ if items.nil? || expired
32
32
  items = getBundle(component, locale)
33
33
  SgtnClient.logger.debug "Putting sources items into cache with key: " + cache_key
34
34
  SgtnClient::CacheUtil.write_cache(cache_key, items)
@@ -15,6 +15,9 @@ module SgtnClient
15
15
  str = getTranslation(component, key, locale)
16
16
  if str.nil?
17
17
  str = SgtnClient::Source.getSource(component, key, SgtnClient::Config.configurations.default)
18
+ if str.nil?
19
+ SgtnClient.logger.error "Can't find the key " + key + " in source path!"
20
+ end
18
21
  end
19
22
  str
20
23
  end
@@ -23,6 +26,10 @@ module SgtnClient
23
26
  str = getTranslation(component, key, locale)
24
27
  if str.nil?
25
28
  str = SgtnClient::Source.getSource(component, key, SgtnClient::Config.configurations.default)
29
+ if str.nil?
30
+ SgtnClient.logger.error "Can't find the key " + key + " in source path!"
31
+ return nil
32
+ end
26
33
  str.to_plural_s(:en, plural_args)
27
34
  else
28
35
  str.to_plural_s(locale, plural_args)
@@ -31,6 +38,9 @@ module SgtnClient
31
38
 
32
39
  def self.getString_f(component, key, args, locale, *optionals)
33
40
  s = getString(component, key, locale, *optionals)
41
+ if s.nil?
42
+ return nil
43
+ end
34
44
  if args.is_a?(Hash)
35
45
  args.each do |source, arg|
36
46
  s.gsub! "{#{source}}", arg
@@ -47,10 +57,14 @@ module SgtnClient
47
57
  if items.nil? || items["messages"] == nil
48
58
  items = {}
49
59
  s = SgtnClient::Source.getSources(component, default)
50
- default_component, value = s.first
51
- items["component"] = component
52
- items["messages"] = value
53
- items["locale"] = 'source'
60
+ if s.nil?
61
+ SgtnClient.logger.error "Can't find the component " + component + " in source path!"
62
+ else
63
+ default_component, value = s.first
64
+ items["component"] = component
65
+ items["messages"] = value
66
+ items["locale"] = 'source'
67
+ end
54
68
  end
55
69
  return items
56
70
  end
@@ -70,8 +84,8 @@ module SgtnClient
70
84
  def self.get_cs(component, locale)
71
85
  flocale = SgtnClient::LocaleUtil.fallback(locale)
72
86
  cache_key = SgtnClient::CacheUtil.get_cachekey(component, flocale)
73
- items = SgtnClient::CacheUtil.get_cache(cache_key)
74
- if items.nil?
87
+ expired, items = SgtnClient::CacheUtil.get_cache(cache_key)
88
+ if items.nil? || expired
75
89
  items = load(component, flocale)
76
90
  if items.nil?
77
91
  items = SgtnClient::Source.getSources(component, SgtnClient::Config.configurations.default)
@@ -12,6 +12,7 @@ module SgtnClient::Core
12
12
  @@data = Hash.new
13
13
  SgtnClient.logger.debug "Cache is enabled!"
14
14
  else
15
+ @@data = nil
15
16
  SgtnClient.logger.debug "Cache is disabled!"
16
17
  end
17
18
  end
@@ -26,11 +27,10 @@ module SgtnClient::Core
26
27
 
27
28
  def self.get(key)
28
29
  if @@data == nil
29
- return nil
30
+ return nil, nil
30
31
  end
31
32
  SgtnClient.logger.debug "Get cache for key: " + key
32
- invalidate
33
- @@data[key][:value] if has(key)
33
+ invalidate(key)
34
34
  end
35
35
 
36
36
  def self.has(key)
@@ -73,18 +73,27 @@ module SgtnClient::Core
73
73
  end
74
74
  end
75
75
 
76
- def self.invalidate
76
+ def self.invalidate(key)
77
77
  @mutex.synchronize do
78
78
  if @@data == nil
79
- return nil
79
+ return nil, nil
80
80
  end
81
81
  SgtnClient.logger.debug "Invalidating expired cache......"
82
82
  now = Time.now
83
- @@data.each {
84
- |k, v|
85
- SgtnClient.logger.debug "Checking cache: key=#{k}, expiredtime=#{v[:expiry]}, now=#{now}, expired=#{(v[:expiry] < now)}"
86
- }
87
- @@data.delete_if {|k, v| v[:expiry] < now}
83
+ if has(key)
84
+ v = @@data[key]
85
+ expired = false
86
+ SgtnClient.logger.debug "Checking cache: key=#{key}, expiredtime=#{v[:expiry]}, now=#{now}, expired=#{(v[:expiry] < now)}"
87
+ if v[:expiry] < now
88
+ SgtnClient.logger.debug "Before deleting the cache: data=#{@@data}"
89
+ @@data.delete(key)
90
+ SgtnClient.logger.debug "After deleting the cache: data=#{@@data}"
91
+ expired = true
92
+ end
93
+ return expired, v[:value]
94
+ else
95
+ return nil, nil
96
+ end
88
97
  end
89
98
  end
90
99
  end
@@ -10,8 +10,8 @@ module SgtnClient
10
10
  class CacheUtil
11
11
 
12
12
  def self.get_cache(cache_key)
13
- items = SgtnClient::Core::Cache.get(cache_key)
14
- return items
13
+ expired, items = SgtnClient::Core::Cache.get(cache_key)
14
+ return expired, items
15
15
  end
16
16
 
17
17
  def self.clear_cache()
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.27
4
+ version: 0.7.0.28
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-26 00:00:00.000000000 Z
11
+ date: 2022-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client