tml 5.5.1 → 5.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tml/api/client.rb +2 -1
- data/lib/tml/cache.rb +47 -3
- data/lib/tml/cache_version.rb +5 -0
- data/lib/tml/version.rb +1 -1
- data/tasks/tml/cache.rake +6 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 067d6c379b9fa534efe1d4976a661e944be70b32
|
4
|
+
data.tar.gz: 1e8fda1be403bd5c23ed4dbb7db013540b8ff92b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5cec2539d2c255bfefdbad7b7c61504e7592fef50a842d14e61055625d9feabcf894d345227e2949d5b2c0efef6411d9e5c03bd41516e937164dbc5f25a111dc
|
7
|
+
data.tar.gz: 60b3cd035e5018c58b1af4896c3087c1cf249cb0c68c2b7a4b635426b4342cfc4b632a41d579a49bdf94747543cb230e3c7504d585d85a81423ba7297478e30e
|
data/lib/tml/api/client.rb
CHANGED
@@ -205,7 +205,8 @@ class Tml::Api::Client < Tml::Base
|
|
205
205
|
|
206
206
|
# get request uses local cache, then CDN
|
207
207
|
data = Tml.cache.fetch(opts[:cache_key]) do
|
208
|
-
|
208
|
+
fetched_data = get_from_cdn(opts[:cache_key]) unless Tml.cache.read_only?
|
209
|
+
fetched_data || {}
|
209
210
|
end
|
210
211
|
|
211
212
|
process_response(data, opts)
|
data/lib/tml/cache.rb
CHANGED
@@ -136,6 +136,7 @@ module Tml
|
|
136
136
|
# do nothing
|
137
137
|
end
|
138
138
|
|
139
|
+
# Pulls cache version from CDN
|
139
140
|
def extract_version(app, version = nil)
|
140
141
|
if version
|
141
142
|
Tml.cache.version.set(version.to_s)
|
@@ -151,12 +152,55 @@ module Tml
|
|
151
152
|
end
|
152
153
|
end
|
153
154
|
|
154
|
-
#
|
155
|
-
def warmup(version = nil)
|
155
|
+
# Warms up cache from CDN or local files
|
156
|
+
def warmup(version = nil, cache_path = nil)
|
157
|
+
if cache_path.nil?
|
158
|
+
warmup_from_cdn(version)
|
159
|
+
else
|
160
|
+
warmup_from_files(version, cache_path)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
# Warms up cache from local files
|
165
|
+
def warmup_from_files(version = nil, cache_path = nil)
|
166
|
+
t0 = Time.now
|
167
|
+
Tml.logger = Logger.new(STDOUT)
|
168
|
+
|
169
|
+
Tml.logger.debug('Starting cache warmup from local files...')
|
170
|
+
version ||= Tml.config.cache[:version]
|
171
|
+
cache_path ||= Tml.config.cache[:path]
|
172
|
+
cache_path = "#{cache_path}/#{version}"
|
173
|
+
|
174
|
+
Tml.cache.version.set(version.to_s)
|
175
|
+
Tml.logger.debug("Warming Up Version: #{Tml.cache.version}")
|
176
|
+
|
177
|
+
application = JSON.parse(File.read("#{cache_path}/application.json"))
|
178
|
+
Tml.cache.store(Tml::Application.cache_key, application)
|
179
|
+
|
180
|
+
sources = JSON.parse(File.read("#{cache_path}/sources.json"))
|
181
|
+
|
182
|
+
application['languages'].each do |lang|
|
183
|
+
locale = lang['locale']
|
184
|
+
|
185
|
+
language = JSON.parse(File.read("#{cache_path}/#{locale}/language.json"))
|
186
|
+
Tml.cache.store(Tml::Language.cache_key(locale), language)
|
187
|
+
|
188
|
+
sources.each do |src|
|
189
|
+
source = JSON.parse(File.read("#{cache_path}/#{locale}/sources/#{src}.json"))
|
190
|
+
Tml.cache.store(Tml::Source.cache_key(locale, src), source)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
t1 = Time.now
|
195
|
+
Tml.logger.debug("Cache warmup took #{t1-t0}s")
|
196
|
+
end
|
197
|
+
|
198
|
+
# Warms up cache from CDN
|
199
|
+
def warmup_from_cdn(version = nil)
|
156
200
|
t0 = Time.now
|
157
201
|
Tml.logger = Logger.new(STDOUT)
|
158
202
|
|
159
|
-
Tml.logger.debug('Starting cache warmup...')
|
203
|
+
Tml.logger.debug('Starting cache warmup from CDN...')
|
160
204
|
app = Tml::Application.new(key: Tml.config.application[:key], cdn_host: Tml.config.application[:cdn_host])
|
161
205
|
extract_version(app, version)
|
162
206
|
|
data/lib/tml/cache_version.rb
CHANGED
@@ -61,6 +61,11 @@ module Tml
|
|
61
61
|
|
62
62
|
# validate that current cache version hasn't expired
|
63
63
|
def validate_cache_version(version)
|
64
|
+
# if cache version is hardcoded, use it
|
65
|
+
if Tml.config.cache[:version]
|
66
|
+
return Tml.config.cache[:version]
|
67
|
+
end
|
68
|
+
|
64
69
|
return version unless version.is_a?(Hash)
|
65
70
|
return 'undefined' unless version['t'].is_a?(Numeric)
|
66
71
|
return version['version'] if cache.read_only?
|
data/lib/tml/version.rb
CHANGED
data/tasks/tml/cache.rake
CHANGED
@@ -14,7 +14,7 @@ namespace :tml do
|
|
14
14
|
|
15
15
|
desc 'warms up dynamic cache'
|
16
16
|
task :warmup => :environment do
|
17
|
-
Tml.cache.warmup
|
17
|
+
Tml.cache.warmup(ENV['version'], ENV['path'])
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -23,9 +23,12 @@ namespace :tml do
|
|
23
23
|
## Local Cache Management
|
24
24
|
##########################################
|
25
25
|
|
26
|
-
desc 'downloads
|
26
|
+
desc 'downloads file cache to local storage'
|
27
27
|
task :download => :environment do
|
28
|
-
Tml.cache.
|
28
|
+
cache_path = ENV['path'] || Tml.cache.default_cache_path
|
29
|
+
version = ENV['version']
|
30
|
+
pp "Downloading #{version} to #{cache_path}..."
|
31
|
+
Tml.cache.download(cache_path, version)
|
29
32
|
end
|
30
33
|
|
31
34
|
desc 'rolls back to the previous version'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.5.
|
4
|
+
version: 5.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Berkovich
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|