Better cache name creation

pull/1022/head
Jasper van Merle 6 years ago
parent 2bbbc66e8c
commit 5dc1437631

@ -205,27 +205,30 @@ class App < Sinatra::Application
].compact ].compact
end end
# Returns a cache name for the service worker to use which changes if any of the assets changes
# When a manifest exist, this name is only created once based on the asset manifest because it never changes without a server restart
# If a manifest does not exist, it is created every time this method is called because the assets can change while the server is running
def service_worker_cache_name def service_worker_cache_name
# Returns the digest of the last modified asset
# When a manifest exist, this digest is only calculated once based on the asset manifest because it never changes without a server restart
# If a manifest does not exist, it is calculated every time this method is called because the assets can change while the server is running
if File.exist?(App.assets_manifest_path) if File.exist?(App.assets_manifest_path)
return @@service_worker_cache_name ||= if defined?(@@service_worker_cache_name)
Sprockets::Manifest return @@service_worker_cache_name
.new(nil, App.assets_manifest_path) end
.files
.values digest = Sprockets::Manifest
.sort_by {|file| file["mtime"]} .new(nil, App.assets_manifest_path)
.reverse .files
.first["digest"] .values
.map {|file| file["digest"]}
.join
return @@service_worker_cache_name ||= Digest::MD5.hexdigest(digest)
else else
last_modified_file = App.sprockets paths = App.sprockets
.each_file .each_file
.to_a .to_a
.reject {|file| file.start_with?(App.docs_path)} .reject {|file| file.start_with?(App.docs_path)}
.max_by {|file| File.mtime(file)}
return App.sprockets.pack_base64digest(App.sprockets.file_digest(last_modified_file)) return App.sprockets.pack_hexdigest(App.sprockets.files_digest(paths))
end end
end end

@ -0,0 +1,14 @@
# Logfile created on 2019-07-10 22:09:26 +0200 by logger.rb/66358
[2019-07-10 22:09:26 +0200 Jasper-PC (9163)] INFO : Starting the New Relic agent version 5.7.0.350 in "production" environment.
[2019-07-10 22:09:26 +0200 Jasper-PC (9163)] INFO : To prevent agent startup add a NEW_RELIC_AGENT_ENABLED=false environment variable or modify the "production" section of your newrelic.yml.
[2019-07-10 22:09:26 +0200 Jasper-PC (9163)] INFO : Reading configuration from newrelic.yml (/home/jasper/Projects/devdocs)
[2019-07-10 22:09:26 +0200 Jasper-PC (9163)] ERROR : No application name configured.
[2019-07-10 22:09:26 +0200 Jasper-PC (9163)] ERROR : The Agent cannot start without at least one. Please check your
[2019-07-10 22:09:26 +0200 Jasper-PC (9163)] ERROR : newrelic.yml and ensure that it is valid and has at least one
[2019-07-10 22:09:26 +0200 Jasper-PC (9163)] ERROR : value set for app_name in the production
[2019-07-10 22:09:26 +0200 Jasper-PC (9163)] ERROR : environment.
[2019-07-10 22:09:26 +0200 Jasper-PC (9163)] INFO : Installing Sinatra instrumentation
[2019-07-10 22:09:26 +0200 Jasper-PC (9163)] INFO : Installing Net instrumentation
[2019-07-10 22:09:26 +0200 Jasper-PC (9163)] INFO : Installing deferred Rack::Builder instrumentation
[2019-07-10 22:09:26 +0200 Jasper-PC (9163)] INFO : Installing Rack::Builder middleware instrumentation
[2019-07-10 22:09:26 +0200 Jasper-PC (9163)] INFO : Finished instrumentation
Loading…
Cancel
Save