diff options
author | Jacob Vosmaer <contact@jacobvosmaer.nl> | 2016-03-03 17:59:47 +0100 |
---|---|---|
committer | Jacob Vosmaer <contact@jacobvosmaer.nl> | 2016-03-03 17:59:47 +0100 |
commit | fc90d9e5896cdcccedb697fd4536f126d10f3f8e (patch) | |
tree | f6b26659982f737e0e8bbc28929bde43325b48de /app/helpers | |
parent | 00cb4a97147a8f760d37c5f6fae11f93ba4ede34 (diff) | |
download | gitlab-ce-fc90d9e5896cdcccedb697fd4536f126d10f3f8e.tar.gz |
Tell clients/proxies to cache raw blob requests
Diffstat (limited to 'app/helpers')
-rw-r--r-- | app/helpers/blob_helper.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/app/helpers/blob_helper.rb b/app/helpers/blob_helper.rb index 7f63a2e2cb4..adb56e49c62 100644 --- a/app/helpers/blob_helper.rb +++ b/app/helpers/blob_helper.rb @@ -152,4 +152,29 @@ module BlobHelper 'application/octet-stream' end end + + def set_cache_headers + if @project.visibility_level == Project::PUBLIC + cache_control = 'public, ' + else + cache_control = 'private, ' + end + + if @ref && @commit && @ref == @commit.id + # This is a link to a commit by its commit SHA. That means that the blob + # is immutable. + cache_control << 'max-age=600' # 10 minutes + else + # A branch or tag points at this blob. That means that the expected blob + # value may change over time. + cache_control << 'max-age=60' # 1 minute + end + + headers['Cache-Control'] = cache_control + headers['ETag'] = @blob.id + end + + def check_etag! + stale?(etag: @blob.id) + end end |