always use etag for caching when cache_key or updated_at are present, add the deploy_sha as a cache buster
This commit is contained in:
parent
44521014a8
commit
a9bf43c1fd
|
@ -51,6 +51,10 @@ module Travis::Api
|
|||
super()
|
||||
end
|
||||
|
||||
def self.deploy_sha
|
||||
@deploy_sha ||= File.exist?('.deploy_sha') ? File.read('.deploy-sha')[0..7] : 'deploy-sha'
|
||||
end
|
||||
|
||||
attr_accessor :app
|
||||
|
||||
def initialize
|
||||
|
@ -64,11 +68,10 @@ module Travis::Api
|
|||
|
||||
memcache_servers = ENV['MEMCACHE_SERVERS']
|
||||
if Travis::Features.feature_active?(:use_rack_cache) && memcache_server
|
||||
namespace = File.read('.deploy-sha')[0..7]
|
||||
use Rack::Cache,
|
||||
verbose: true,
|
||||
metastore: "memcached://#{memcache_servers}/#{namespace}",
|
||||
entitystore: "memcached://#{memcache_servers}/#{namespace}"
|
||||
metastore: "memcached://#{memcache_servers}/#{self.class.deploy_sha}",
|
||||
entitystore: "memcached://#{memcache_servers}/#{self.class.deploy_sha}"
|
||||
end
|
||||
|
||||
use Rack::Deflater
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
module Travis::Api::App::Responders
|
||||
require 'digest/md5'
|
||||
|
||||
module Travis::Api
|
||||
class App
|
||||
module Responders
|
||||
class Service < Base
|
||||
include Helpers::Accept
|
||||
|
||||
def apply?
|
||||
resource.respond_to?(:run)
|
||||
end
|
||||
|
@ -22,20 +28,26 @@ module Travis::Api::App::Responders
|
|||
endpoint.cache_control :no_cache
|
||||
end
|
||||
|
||||
endpoint.etag resource.cache_key if cache_key?
|
||||
endpoint.last_modified resource.updated_at if updated_at?
|
||||
endpoint.etag cache_key if cache_key
|
||||
end
|
||||
|
||||
def final?
|
||||
resource.respond_to?(:final?) && resource.final?
|
||||
end
|
||||
|
||||
def updated_at?
|
||||
def cache_key
|
||||
cache_key ||= begin
|
||||
key = resource_cache_key || resource_updated_at
|
||||
Digest::MD5.hexdigest([App.deploy_sha, key].join('-')) if key
|
||||
end
|
||||
end
|
||||
|
||||
def resource_cache_key
|
||||
resource.respond_to?(:updated_at) && resource.updated_at
|
||||
end
|
||||
|
||||
def cache_key?
|
||||
resource.respond_to?(:cache_key) && resource.cache_key
|
||||
def resource_updated_at
|
||||
resource.respond_to?(:updated_at) && resource.updated_at.try(:strftime, '%FT%T%:z')
|
||||
end
|
||||
|
||||
# Services potentially return all sorts of things
|
||||
|
@ -52,3 +64,5 @@ module Travis::Api::App::Responders
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user