Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
2a934aa3
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,发现更多精彩内容 >>
提交
2a934aa3
编写于
1月 11, 2018
作者:
R
Ryuta Kamizono
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #30268 from ignatiusreza/instrumentation
add instrumentation for read_multi
上级
013a8abd
62023884
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
64 addition
and
49 deletion
+64
-49
activesupport/CHANGELOG.md
activesupport/CHANGELOG.md
+4
-0
activesupport/lib/active_support/cache.rb
activesupport/lib/active_support/cache.rb
+36
-21
activesupport/lib/active_support/cache/mem_cache_store.rb
activesupport/lib/active_support/cache/mem_cache_store.rb
+18
-22
activesupport/test/cache/cache_store_write_multi_test.rb
activesupport/test/cache/cache_store_write_multi_test.rb
+6
-6
未找到文件。
activesupport/CHANGELOG.md
浏览文件 @
2a934aa3
*
Add missing instrumentation for
`read_multi`
in
`ActiveSupport::Cache::Store`
.
*Ignatius Reza Lesmana*
*
`assert_changes`
will always assert that the expression changes,
regardless of
`from:`
and
`to:`
argument combinations.
...
...
activesupport/lib/active_support/cache.rb
浏览文件 @
2a934aa3
...
...
@@ -357,23 +357,11 @@ def read_multi(*names)
options
=
names
.
extract_options!
options
=
merged_options
(
options
)
results
=
{}
names
.
each
do
|
name
|
key
=
normalize_key
(
name
,
options
)
version
=
normalize_version
(
name
,
options
)
entry
=
read_entry
(
key
,
options
)
if
entry
if
entry
.
expired?
delete_entry
(
key
,
options
)
elsif
entry
.
mismatched?
(
version
)
# Skip mismatched versions
else
results
[
name
]
=
entry
.
value
end
instrument
:read_multi
,
names
,
options
do
|
payload
|
read_multi_entries
(
names
,
options
).
tap
do
|
results
|
payload
[
:hits
]
=
results
.
keys
end
end
results
end
# Cache Storage API to write multiple values at once.
...
...
@@ -414,14 +402,19 @@ def fetch_multi(*names)
options
=
names
.
extract_options!
options
=
merged_options
(
options
)
read_multi
(
*
names
,
options
).
tap
do
|
results
|
writes
=
{}
instrument
:read_multi
,
names
,
options
do
|
payload
|
read_multi_entries
(
names
,
options
).
tap
do
|
results
|
payload
[
:hits
]
=
results
.
keys
payload
[
:super_operation
]
=
:fetch_multi
(
names
-
results
.
keys
).
each
do
|
name
|
results
[
name
]
=
writes
[
name
]
=
yield
(
name
)
end
writes
=
{}
write_multi
writes
,
options
(
names
-
results
.
keys
).
each
do
|
name
|
results
[
name
]
=
writes
[
name
]
=
yield
(
name
)
end
write_multi
writes
,
options
end
end
end
...
...
@@ -538,6 +531,28 @@ def write_entry(key, entry, options)
raise
NotImplementedError
.
new
end
# Reads multiple entries from the cache implementation. Subclasses MAY
# implement this method.
def
read_multi_entries
(
names
,
options
)
results
=
{}
names
.
each
do
|
name
|
key
=
normalize_key
(
name
,
options
)
version
=
normalize_version
(
name
,
options
)
entry
=
read_entry
(
key
,
options
)
if
entry
if
entry
.
expired?
delete_entry
(
key
,
options
)
elsif
entry
.
mismatched?
(
version
)
# Skip mismatched versions
else
results
[
name
]
=
entry
.
value
end
end
end
results
end
# Writes multiple entries to the cache implementation. Subclasses MAY
# implement this method.
def
write_multi_entries
(
hash
,
options
)
...
...
activesupport/lib/active_support/cache/mem_cache_store.rb
浏览文件 @
2a934aa3
...
...
@@ -91,28 +91,6 @@ def initialize(*addresses)
end
end
# Reads multiple values from the cache using a single call to the
# servers for all keys. Options can be passed in the last argument.
def
read_multi
(
*
names
)
options
=
names
.
extract_options!
options
=
merged_options
(
options
)
keys_to_names
=
Hash
[
names
.
map
{
|
name
|
[
normalize_key
(
name
,
options
),
name
]
}]
raw_values
=
@data
.
get_multi
(
keys_to_names
.
keys
)
values
=
{}
raw_values
.
each
do
|
key
,
value
|
entry
=
deserialize_entry
(
value
)
unless
entry
.
expired?
||
entry
.
mismatched?
(
normalize_version
(
keys_to_names
[
key
],
options
))
values
[
keys_to_names
[
key
]]
=
entry
.
value
end
end
values
end
# Increment a cached value. This method uses the memcached incr atomic
# operator and can only be used on values written with the :raw option.
# Calling it on a value not stored with :raw will initialize that value
...
...
@@ -170,6 +148,24 @@ def write_entry(key, entry, options)
end
end
# Reads multiple entries from the cache implementation.
def
read_multi_entries
(
names
,
options
)
keys_to_names
=
Hash
[
names
.
map
{
|
name
|
[
normalize_key
(
name
,
options
),
name
]
}]
raw_values
=
@data
.
get_multi
(
keys_to_names
.
keys
)
values
=
{}
raw_values
.
each
do
|
key
,
value
|
entry
=
deserialize_entry
(
value
)
unless
entry
.
expired?
||
entry
.
mismatched?
(
normalize_version
(
keys_to_names
[
key
],
options
))
values
[
keys_to_names
[
key
]]
=
entry
.
value
end
end
values
end
# Delete an entry from the cache.
def
delete_entry
(
key
,
options
)
rescue_error_with
(
false
)
{
@data
.
delete
(
key
)
}
...
...
activesupport/test/cache/cache_store_write_multi_test.rb
浏览文件 @
2a934aa3
...
...
@@ -19,7 +19,7 @@ class CacheStoreWriteMultiEntriesStoreProviderInterfaceTest < ActiveSupport::Tes
class
CacheStoreWriteMultiInstrumentationTest
<
ActiveSupport
::
TestCase
setup
do
@cache
=
ActiveSupport
::
Cache
.
lookup_store
(
:
null
_store
)
@cache
=
ActiveSupport
::
Cache
.
lookup_store
(
:
memory
_store
)
end
test
"instrumentation"
do
...
...
@@ -35,15 +35,15 @@ class CacheStoreWriteMultiInstrumentationTest < ActiveSupport::TestCase
end
test
"instrumentation with fetch_multi as super operation"
do
skip
"fetch_multi isn't instrumented yet"
@cache
.
write
(
"b"
,
"bb"
)
events
=
with_instrumentation
"
write
_multi"
do
events
=
with_instrumentation
"
read
_multi"
do
@cache
.
fetch_multi
(
"a"
,
"b"
)
{
|
key
|
key
*
2
}
end
assert_equal
%w[ cache_
write
_multi.active_support ]
,
events
.
map
(
&
:name
)
assert_
nil
events
[
0
].
payload
[
:super_operation
]
assert
!
events
[
0
].
payload
[
:hit
]
assert_equal
%w[ cache_
read
_multi.active_support ]
,
events
.
map
(
&
:name
)
assert_
equal
:fetch_multi
,
events
[
0
].
payload
[
:super_operation
]
assert
_equal
[
"b"
],
events
[
0
].
payload
[
:hits
]
end
private
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录