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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: caf33060b73c70df64aaec5d6c65af53e5a79fa5
4
- data.tar.gz: 8943817182ebd7a933122e8599c44606a02a291c
3
+ metadata.gz: 067d6c379b9fa534efe1d4976a661e944be70b32
4
+ data.tar.gz: 1e8fda1be403bd5c23ed4dbb7db013540b8ff92b
5
5
  SHA512:
6
- metadata.gz: 9a852cc091ec891903b91ebbd6438e87aedb431146e2b4a73fe0e24a2ee82e771fbe04a989fd0165d21ff1889167b19298f8506f6af856af957e65dfb6f39177
7
- data.tar.gz: a8063602bb5db4c83ed368281a0a107d5889d62c80a0fd509406a5a589fef30aa65aac308dc1c379c7b2c259e8f64921402ad1203b4d409015562518999c99ee
6
+ metadata.gz: 5cec2539d2c255bfefdbad7b7c61504e7592fef50a842d14e61055625d9feabcf894d345227e2949d5b2c0efef6411d9e5c03bd41516e937164dbc5f25a111dc
7
+ data.tar.gz: 60b3cd035e5018c58b1af4896c3087c1cf249cb0c68c2b7a4b635426b4342cfc4b632a41d579a49bdf94747543cb230e3c7504d585d85a81423ba7297478e30e
@@ -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
- Tml.cache.read_only? ? nil : get_from_cdn(opts[:cache_key])
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
- # warmup cache
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
 
@@ -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
@@ -31,7 +31,7 @@
31
31
  #++
32
32
 
33
33
  module Tml
34
- VERSION = '5.5.1'
34
+ VERSION = '5.5.2'
35
35
 
36
36
  def self.full_version
37
37
  "tml-ruby v#{Tml::VERSION} (Faraday v#{Faraday::VERSION})"
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 local file cache'
26
+ desc 'downloads file cache to local storage'
27
27
  task :download => :environment do
28
- Tml.cache.download
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.1
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-02 00:00:00.000000000 Z
11
+ date: 2016-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday