Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
41bc9c46
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
41bc9c46
编写于
3月 07, 2016
作者:
J
Jacob Vosmaer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor caching code
上级
a215e2ee
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
18 addition
and
11 deletion
+18
-11
app/controllers/projects/avatars_controller.rb
app/controllers/projects/avatars_controller.rb
+3
-2
app/controllers/projects/raw_controller.rb
app/controllers/projects/raw_controller.rb
+2
-2
app/helpers/blob_helper.rb
app/helpers/blob_helper.rb
+10
-7
app/models/blob.rb
app/models/blob.rb
+3
-0
未找到文件。
app/controllers/projects/avatars_controller.rb
浏览文件 @
41bc9c46
...
...
@@ -7,8 +7,9 @@ class Projects::AvatarsController < Projects::ApplicationController
@blob
=
@repository
.
blob_at_branch
(
'master'
,
@project
.
avatar_in_git
)
if
@blob
headers
[
'X-Content-Type-Options'
]
=
'nosniff'
set_cache_headers
check_etag!
return
if
cached_blob?
headers
.
store
(
*
Gitlab
::
Workhorse
.
send_git_blob
(
@repository
,
@blob
))
headers
[
'Content-Disposition'
]
=
'inline'
headers
[
'Content-Type'
]
=
safe_content_type
(
@blob
)
...
...
app/controllers/projects/raw_controller.rb
浏览文件 @
41bc9c46
...
...
@@ -12,8 +12,8 @@ class Projects::RawController < Projects::ApplicationController
if
@blob
headers
[
'X-Content-Type-Options'
]
=
'nosniff'
check_etag!
set_cache_headers
return
if
cached_blob?
if
@blob
.
lfs_pointer?
send_lfs_object
...
...
app/helpers/blob_helper.rb
浏览文件 @
41bc9c46
...
...
@@ -153,7 +153,10 @@ module BlobHelper
end
end
def
set_cache_headers
def
cached_blob?
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
...
...
@@ -162,19 +165,19 @@ module BlobHelper
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
# 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
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
max_age
=
Blob
::
CACHE_TIME
end
cache_control
<<
"max-age=
#{
max_age
}
"
headers
[
'Cache-Control'
]
=
cache_control
headers
[
'ETag'
]
=
@blob
.
id
end
def
check_etag!
stale?
(
etag:
@blob
.
id
)
!
stale
end
end
app/models/blob.rb
浏览文件 @
41bc9c46
# Blob is a Rails-specific wrapper around Gitlab::Git::Blob objects
class
Blob
<
SimpleDelegator
CACHE_TIME
=
60
# Cache raw blobs referred to by a (mutable) ref for 1 minute
CACHE_TIME_IMMUTABLE
=
3600
# Cache blobs referred to by an immutable reference for 1 hour
# Wrap a Gitlab::Git::Blob object, or return nil when given nil
#
# This method prevents the decorated object from evaluating to "truthy" when
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录