Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
a284d307
Commit
a284d307
authored
Mar 07, 2016
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use Rails etag/cache_control helpers
parent
41bc9c46
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
11 deletions
+4
-11
app/helpers/blob_helper.rb
app/helpers/blob_helper.rb
+4
-11
No files found.
app/helpers/blob_helper.rb
View file @
a284d307
...
@@ -157,27 +157,20 @@ module BlobHelper
...
@@ -157,27 +157,20 @@ module BlobHelper
stale
=
stale?
(
etag:
@blob
.
id
)
# The #stale? method sets cache headers.
stale
=
stale?
(
etag:
@blob
.
id
)
# The #stale? method sets cache headers.
# Because we are opionated we set the cache headers ourselves.
# Because we are opionated we set the cache headers ourselves.
if
@project
.
visibility_level
==
Project
::
PUBLIC
response
.
cache_control
[
:public
]
=
@project
.
public?
cache_control
=
'public, '
else
cache_control
=
'private, '
end
if
@ref
&&
@commit
&&
@ref
==
@commit
.
id
if
@ref
&&
@commit
&&
@ref
==
@commit
.
id
# This is a link to a commit by its commit SHA. That means that the blob
# 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
# is immutable. The only reason to invalidate the cache is if the commit
# was deleted or if the user lost access to the repository.
# 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
else
# A branch or tag points at this blob. That means that the expected blob
# A branch or tag points at this blob. That means that the expected blob
# value may change over time.
# value may change over time.
max_age
=
Blob
::
CACHE_TIME
response
.
cache_control
[
:max_age
]
=
Blob
::
CACHE_TIME
end
end
cache_control
<<
"max-age=
#{
max_age
}
"
response
.
etag
=
@blob
.
id
headers
[
'Cache-Control'
]
=
cache_control
headers
[
'ETag'
]
=
@blob
.
id
!
stale
!
stale
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment