Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
756d7762
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,发现更多精彩内容 >>
提交
756d7762
编写于
6月 17, 2010
作者:
H
Hongli Lai (Phusion)
提交者:
José Valim
6月 21, 2010
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Allow instrumentation of cache hits and misses. [#4888 state:resolved]
Signed-off-by:
N
José Valim
<
jose.valim@gmail.com
>
上级
f8166669
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
40 addition
and
25 deletion
+40
-25
activesupport/lib/active_support/cache.rb
activesupport/lib/active_support/cache.rb
+40
-25
未找到文件。
activesupport/lib/active_support/cache.rb
浏览文件 @
756d7762
...
...
@@ -267,27 +267,39 @@ def self.instrument
# :bar
# end
# cache.fetch("foo") # => "bar"
def
fetch
(
name
,
options
=
nil
,
&
block
)
options
=
merged_options
(
options
)
key
=
namespaced_key
(
name
,
options
)
entry
=
instrument
(
:read
,
name
,
options
)
{
read_entry
(
key
,
options
)
}
unless
options
[
:force
]
if
entry
&&
entry
.
expired?
race_ttl
=
options
[
:race_condition_ttl
].
to_f
if
race_ttl
and
Time
.
now
.
to_f
-
entry
.
expires_at
<=
race_ttl
entry
.
expires_at
=
Time
.
now
+
race_ttl
write_entry
(
key
,
entry
,
:expires_in
=>
race_ttl
*
2
)
else
delete_entry
(
key
,
options
)
def
fetch
(
name
,
options
=
nil
)
if
block_given?
options
=
merged_options
(
options
)
key
=
namespaced_key
(
name
,
options
)
unless
options
[
:force
]
entry
=
instrument
(
:read
,
name
,
options
)
do
|
payload
|
payload
[
:super_operation
]
=
:fetch
if
payload
read_entry
(
key
,
options
)
end
end
if
entry
&&
entry
.
expired?
race_ttl
=
options
[
:race_condition_ttl
].
to_f
if
race_ttl
and
Time
.
now
.
to_f
-
entry
.
expires_at
<=
race_ttl
entry
.
expires_at
=
Time
.
now
+
race_ttl
write_entry
(
key
,
entry
,
:expires_in
=>
race_ttl
*
2
)
else
delete_entry
(
key
,
options
)
end
entry
=
nil
end
entry
=
nil
end
if
entry
entry
.
value
elsif
block_given?
result
=
instrument
(
:generate
,
name
,
options
,
&
block
)
write
(
name
,
result
,
options
)
result
if
entry
instrument
(
:fetch_hit
,
name
,
options
)
{
|
payload
|
}
entry
.
value
else
result
=
instrument
(
:generate
,
name
,
options
)
do
|
payload
|
yield
end
write
(
name
,
result
,
options
)
result
end
else
read
(
name
,
options
)
end
end
...
...
@@ -299,16 +311,19 @@ def fetch(name, options = nil, &block)
def
read
(
name
,
options
=
nil
)
options
=
merged_options
(
options
)
key
=
namespaced_key
(
name
,
options
)
instrument
(
:read
,
name
,
options
)
do
instrument
(
:read
,
name
,
options
)
do
|
payload
|
entry
=
read_entry
(
key
,
options
)
if
entry
if
entry
.
expired?
delete_entry
(
key
,
options
)
payload
[
:hit
]
=
false
if
payload
nil
else
payload
[
:hit
]
=
true
if
payload
entry
.
value
end
else
payload
[
:hit
]
=
false
if
payload
nil
end
end
...
...
@@ -345,7 +360,7 @@ def read_multi(*names)
# +options+.
def
write
(
name
,
value
,
options
=
nil
)
options
=
merged_options
(
options
)
instrument
(
:write
,
name
,
options
)
do
instrument
(
:write
,
name
,
options
)
do
|
payload
|
entry
=
Entry
.
new
(
value
,
options
)
write_entry
(
namespaced_key
(
name
,
options
),
entry
,
options
)
end
...
...
@@ -356,7 +371,7 @@ def write(name, value, options = nil)
# Options are passed to the underlying cache implementation.
def
delete
(
name
,
options
=
nil
)
options
=
merged_options
(
options
)
instrument
(
:delete
,
name
)
do
instrument
(
:delete
,
name
)
do
|
payload
|
delete_entry
(
namespaced_key
(
name
,
options
),
options
)
end
end
...
...
@@ -366,7 +381,7 @@ def delete(name, options = nil)
# Options are passed to the underlying cache implementation.
def
exist?
(
name
,
options
=
nil
)
options
=
merged_options
(
options
)
instrument
(
:exist?
,
name
)
do
instrument
(
:exist?
,
name
)
do
|
payload
|
entry
=
read_entry
(
namespaced_key
(
name
,
options
),
options
)
if
entry
&&
!
entry
.
expired?
true
...
...
@@ -502,9 +517,9 @@ def instrument(operation, key, options = nil)
if
self
.
class
.
instrument
payload
=
{
:key
=>
key
}
payload
.
merge!
(
options
)
if
options
.
is_a?
(
Hash
)
ActiveSupport
::
Notifications
.
instrument
(
"cache_
#{
operation
}
.active_support"
,
payload
){
yield
}
ActiveSupport
::
Notifications
.
instrument
(
"cache_
#{
operation
}
.active_support"
,
payload
){
yield
(
payload
)
}
else
yield
yield
(
nil
)
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录