summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Vosmaer <contact@jacobvosmaer.nl>2016-03-07 16:49:46 +0100
committerJacob Vosmaer <contact@jacobvosmaer.nl>2016-03-07 16:49:46 +0100
commita284d307838adf44080c43e4f553fe60b3495ffe (patch)
tree8c7618c2b4248cd8c9bcd9e0c5279aa6b54e2b42
parent41bc9c463c187396e47b4a942965de6ecddca5a1 (diff)
downloadgitlab-ce-cache-raw-2.tar.gz
Use Rails etag/cache_control helperscache-raw-2
-rw-r--r--app/helpers/blob_helper.rb15
1 files changed, 4 insertions, 11 deletions
diff --git a/app/helpers/blob_helper.rb b/app/helpers/blob_helper.rb
index e5c0ed4b7bd..0f77b3b299a 100644
--- a/app/helpers/blob_helper.rb
+++ b/app/helpers/blob_helper.rb
@@ -157,27 +157,20 @@ module BlobHelper
stale = stale?(etag: @blob.id) # The #stale? method sets cache headers.
# Because we are opionated we set the cache headers ourselves.
- if @project.visibility_level == Project::PUBLIC
- cache_control = 'public, '
- else
- cache_control = 'private, '
- end
+ response.cache_control[:public] = @project.public?
if @ref && @commit && @ref == @commit.id
# This is a link to a commit by its commit SHA. That means that the blob
# is immutable. The only reason to invalidate the cache is if the commit
# was deleted or if the user lost access to the repository.
- max_age = Blob::CACHE_TIME_IMMUTABLE
+ response.cache_control[:max_age] = Blob::CACHE_TIME_IMMUTABLE
else
# A branch or tag points at this blob. That means that the expected blob
# value may change over time.
- max_age = Blob::CACHE_TIME
+ response.cache_control[:max_age] = Blob::CACHE_TIME
end
- cache_control << "max-age=#{max_age}"
- headers['Cache-Control'] = cache_control
- headers['ETag'] = @blob.id
-
+ response.etag = @blob.id
!stale
end
end