singleton-client-test 0.7.0.22 → 0.7.0.23
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sgtn-client/api/source.rb +4 -10
- data/lib/sgtn-client/api/translation.rb +1 -7
- data/lib/sgtn-client/core/cache.rb +32 -23
- data/lib/sgtn-client/sgtn-client.rb +1 -0
- data/lib/sgtn-client/util/file-util.rb +32 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa4b0bc9356e4e2a2b02be92de8e534093d825d903d7494a121c94fdc4153a3d
|
4
|
+
data.tar.gz: 7531f9a8b73f2267c6240ef0099ee4fcb6d68a52e957ec1c498d0fa573e2de7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85ebde63fec80442f71486ff98f15553eb2521d6b672b76965c292b89faf05ba886cd89016bf74fe1be817066a9cddb13ed8beeb5f23e8ee14be03ab82feb297
|
7
|
+
data.tar.gz: 045f61ca5068ae70dc8a1220b052f390d09972c3f3e7be71f757b146e741a4e99ce3888033256c5503861951af6cd76e93296aa855c7ed28d56e613f21776970
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'erb'
|
2
|
-
require 'yaml'
|
3
1
|
|
4
2
|
module SgtnClient
|
5
3
|
|
@@ -45,9 +43,10 @@ module SgtnClient
|
|
45
43
|
SgtnClient::Config.configurations.default = locale
|
46
44
|
source_bundle = SgtnClient::Config.configurations[env]["source_bundle"]
|
47
45
|
SgtnClient.logger.debug "Loading [" + locale + "] source bundles from path: " + source_bundle
|
48
|
-
Dir.
|
46
|
+
Dir.foreach(source_bundle) do |component|
|
47
|
+
next if component == '.' || component == '..'
|
49
48
|
yamlfile = File.join(source_bundle, component + "/" + locale + ".yml")
|
50
|
-
bundle = read_yml(yamlfile)
|
49
|
+
bundle = SgtnClient::FileUtil.read_yml(yamlfile)
|
51
50
|
cachekey = SgtnClient::CacheUtil.get_cachekey(component, locale)
|
52
51
|
SgtnClient::CacheUtil.write_cache(cachekey,bundle)
|
53
52
|
end
|
@@ -60,18 +59,13 @@ module SgtnClient
|
|
60
59
|
bundlepath = source_bundle + "/" + component + "/" + locale + ".yml"
|
61
60
|
SgtnClient.logger.debug "Getting source from bundle: " + bundlepath
|
62
61
|
begin
|
63
|
-
bundle = read_yml(bundlepath)
|
62
|
+
bundle = SgtnClient::FileUtil.read_yml(bundlepath)
|
64
63
|
rescue => exception
|
65
64
|
SgtnClient.logger.error exception.message
|
66
65
|
end
|
67
66
|
return bundle
|
68
67
|
end
|
69
68
|
|
70
|
-
def self.read_yml(file_name)
|
71
|
-
erb = ERB.new(File.read(file_name))
|
72
|
-
erb.filename = file_name
|
73
|
-
YAML.load(erb.result)
|
74
|
-
end
|
75
69
|
end
|
76
70
|
|
77
71
|
end
|
@@ -101,13 +101,7 @@ module SgtnClient
|
|
101
101
|
translation_bundle = SgtnClient::Config.configurations[env]["translation_bundle"]
|
102
102
|
bundlepath = translation_bundle + "/" + product_name + "/" + version + "/" + component + "/messages_" + locale + ".json"
|
103
103
|
SgtnClient.logger.debug "Getting translations from offline bundle: " + bundlepath
|
104
|
-
|
105
|
-
file = File.read(bundlepath)
|
106
|
-
data_hash = MultiJson.load(file)
|
107
|
-
rescue => exception
|
108
|
-
SgtnClient.logger.error exception.message
|
109
|
-
end
|
110
|
-
return data_hash
|
104
|
+
SgtnClient::FileUtil.read_json(bundlepath)
|
111
105
|
end
|
112
106
|
|
113
107
|
def self.get_server(component, locale)
|
@@ -6,6 +6,7 @@ module SgtnClient::Core
|
|
6
6
|
|
7
7
|
def self.initialize(disabled=false, opts={})
|
8
8
|
$opts = opts
|
9
|
+
@mutex = Mutex.new
|
9
10
|
SgtnClient.logger.debug "Initialize cache......"
|
10
11
|
if disabled == false
|
11
12
|
$data = Hash.new
|
@@ -41,42 +42,50 @@ module SgtnClient::Core
|
|
41
42
|
end
|
42
43
|
|
43
44
|
def self.put(key, value, ttl=nil)
|
44
|
-
|
45
|
-
|
45
|
+
@mutex.synchronize do
|
46
|
+
if $data == nil
|
47
|
+
return nil
|
48
|
+
end
|
49
|
+
ttl ||= @opts[:ttl]
|
50
|
+
# hours from new
|
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)
|
46
53
|
end
|
47
|
-
ttl ||= @opts[:ttl]
|
48
|
-
# hours from new
|
49
|
-
SgtnClient.logger.debug "Put cache for key '" + key + "' with expired time at'" + (Time.now + ttl*60).to_s
|
50
|
-
$data[key] = Entry.new(Time.now + ttl*60, value)
|
51
54
|
end
|
52
55
|
|
53
56
|
def self.delete(key)
|
54
|
-
|
55
|
-
|
57
|
+
@mutex.synchronize do
|
58
|
+
if $data == nil
|
59
|
+
return nil
|
60
|
+
end
|
61
|
+
SgtnClient.logger.debug "Delete cache for key: " + key
|
62
|
+
$data.delete key
|
56
63
|
end
|
57
|
-
SgtnClient.logger.debug "Delete cache for key: " + key
|
58
|
-
$data.delete key
|
59
64
|
end
|
60
65
|
|
61
66
|
def self.clear
|
62
|
-
|
63
|
-
|
67
|
+
@mutex.synchronize do
|
68
|
+
if $data == nil
|
69
|
+
return nil
|
70
|
+
end
|
71
|
+
SgtnClient.logger.debug "Clear cache!"
|
72
|
+
$data = Hash.new
|
64
73
|
end
|
65
|
-
SgtnClient.logger.debug "Clear cache!"
|
66
|
-
$data = Hash.new
|
67
74
|
end
|
68
75
|
|
69
76
|
def self.invalidate
|
70
|
-
|
71
|
-
|
77
|
+
@mutex.synchronize do
|
78
|
+
if $data == nil
|
79
|
+
return nil
|
80
|
+
end
|
81
|
+
SgtnClient.logger.debug "Invalidating expired cache......"
|
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}
|
72
88
|
end
|
73
|
-
SgtnClient.logger.debug "Invalidating expired cache......"
|
74
|
-
now = Time.now
|
75
|
-
$data.each {
|
76
|
-
|k, v|
|
77
|
-
SgtnClient.logger.debug "Checking cache: key=#{k}, expiredtime=#{v[:expiry]}, now=#{now}, expired=#{(v[:expiry] < now)}"
|
78
|
-
}
|
79
|
-
$data.delete_if {|k, v| v[:expiry] < now}
|
80
89
|
end
|
81
90
|
end
|
82
91
|
|
@@ -11,6 +11,7 @@ module SgtnClient
|
|
11
11
|
autoload :Exceptions, "sgtn-client/core/exceptions"
|
12
12
|
autoload :ValidateUtil, "sgtn-client/util/validate-util"
|
13
13
|
autoload :LocaleUtil, "sgtn-client/util/locale-util"
|
14
|
+
autoload :FileUtil, "sgtn-client/util/file-util"
|
14
15
|
|
15
16
|
module Formatters
|
16
17
|
autoload :PluralFormatter, "sgtn-client/formatters/plurals/plural_formatter"
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module SgtnClient
|
5
|
+
|
6
|
+
class FileUtil
|
7
|
+
|
8
|
+
@mutex = Mutex.new
|
9
|
+
|
10
|
+
def self.read_json(bundlepath)
|
11
|
+
@mutex.synchronize do
|
12
|
+
data_hash = nil
|
13
|
+
begin
|
14
|
+
file = File.read(bundlepath)
|
15
|
+
data_hash = MultiJson.load(file)
|
16
|
+
rescue => exception
|
17
|
+
SgtnClient.logger.error exception.message
|
18
|
+
end
|
19
|
+
return data_hash
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.read_yml(file_name)
|
24
|
+
@mutex.synchronize do
|
25
|
+
erb = ERB.new(File.read(file_name))
|
26
|
+
erb.filename = file_name
|
27
|
+
YAML.load(erb.result)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
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.23
|
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:
|
11
|
+
date: 2022-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -282,6 +282,7 @@ files:
|
|
282
282
|
- lib/sgtn-client/formatters/plurals/plural_formatter.rb
|
283
283
|
- lib/sgtn-client/sgtn-client.rb
|
284
284
|
- lib/sgtn-client/util/cache-util.rb
|
285
|
+
- lib/sgtn-client/util/file-util.rb
|
285
286
|
- lib/sgtn-client/util/locale-util.rb
|
286
287
|
- lib/sgtn-client/util/validate-util.rb
|
287
288
|
- lib/singleton-ruby.rb
|
@@ -305,7 +306,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
305
306
|
- !ruby/object:Gem::Version
|
306
307
|
version: '0'
|
307
308
|
requirements: []
|
308
|
-
rubygems_version: 3.
|
309
|
+
rubygems_version: 3.3.3
|
309
310
|
signing_key:
|
310
311
|
specification_version: 4
|
311
312
|
summary: Singleton Ruby client
|