Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Vosmaer <contact@jacobvosmaer.nl>2016-03-03 19:59:47 +0300
committerJacob Vosmaer <contact@jacobvosmaer.nl>2016-03-03 19:59:47 +0300
commitfc90d9e5896cdcccedb697fd4536f126d10f3f8e (patch)
treef6b26659982f737e0e8bbc28929bde43325b48de /app/helpers/blob_helper.rb
parent00cb4a97147a8f760d37c5f6fae11f93ba4ede34 (diff)
Tell clients/proxies to cache raw blob requests
Diffstat (limited to 'app/helpers/blob_helper.rb')
-rw-r--r--app/helpers/blob_helper.rb25
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