Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
77cf5cfc
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
77cf5cfc
编写于
7月 30, 2013
作者:
R
Rafael Mendonça França
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #11664 from thedarkone/digestor-thread-safety
AV::Digestor thread safety fixes
上级
2d53ee0f
650810fc
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
29 addition
and
9 deletion
+29
-9
actionview/lib/action_view/digestor.rb
actionview/lib/action_view/digestor.rb
+29
-9
未找到文件。
actionview/lib/action_view/digestor.rb
浏览文件 @
77cf5cfc
require
'thread_safe'
require
'action_view/dependency_tracker'
require
'monitor'
module
ActionView
class
Digestor
cattr_reader
(
:cache
)
@@cache
=
ThreadSafe
::
Cache
.
new
def
self
.
digest
(
name
,
format
,
finder
,
options
=
{})
cache_key
=
([
name
,
format
]
+
Array
.
wrap
(
options
[
:dependencies
])).
join
(
'.'
)
@@cache
.
fetch
(
cache_key
)
do
@@cache
[
cache_key
]
||=
nil
if
options
[
:partial
]
# Prevent re-entry
@@cache
=
ThreadSafe
::
Cache
.
new
@@digest_monitor
=
Monitor
.
new
class
<<
self
def
digest
(
name
,
format
,
finder
,
options
=
{})
cache_key
=
([
name
,
format
]
+
Array
.
wrap
(
options
[
:dependencies
])).
join
(
'.'
)
# this is a correctly done double-checked locking idiom
# (ThreadSafe::Cache's lookups have volatile semantics)
@@cache
[
cache_key
]
||
@@digest_monitor
.
synchronize
do
@@cache
.
fetch
(
cache_key
)
do
# re-check under lock
compute_and_store_digest
(
cache_key
,
name
,
format
,
finder
,
options
)
end
end
end
klass
=
options
[
:partial
]
||
name
.
include?
(
"/_"
)
?
PartialDigestor
:
Digestor
digest
=
klass
.
new
(
name
,
format
,
finder
,
options
).
digest
private
def
compute_and_store_digest
(
cache_key
,
name
,
format
,
finder
,
options
)
# called under @@digest_monitor lock
klass
=
if
options
[
:partial
]
||
name
.
include?
(
"/_"
)
# Prevent re-entry or else recursive templates will blow the stack.
# There is no need to worry about other threads seeing the +false+ value,
# as they will then have to wait for this thread to let go of the @@digest_monitor lock.
pre_stored
=
@@cache
.
put_if_absent
(
cache_key
,
false
).
nil?
# put_if_absent returns nil on insertion
PartialDigestor
else
Digestor
end
@@cache
[
cache_key
]
=
digest
# Store the value
@@cache
[
cache_key
]
=
digest
=
klass
.
new
(
name
,
format
,
finder
,
options
).
digest
# Store the actual digest
ensure
@@cache
.
delete_pair
(
cache_key
,
false
)
if
pre_stored
&&
!
digest
# something went wrong, make sure not to corrupt the @@cache
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录