Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
c90c9b2d
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,发现更多精彩内容 >>
提交
c90c9b2d
编写于
6月 29, 2015
作者:
K
Kasper Timm Hansen
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #20538 from repinel/fix-render-caching-issue
Fix cache issue when different partials use the same collection
上级
aba43b7d
da167457
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
36 addition
and
16 deletion
+36
-16
actionview/CHANGELOG.md
actionview/CHANGELOG.md
+9
-0
actionview/lib/action_view/helpers/cache_helper.rb
actionview/lib/action_view/helpers/cache_helper.rb
+13
-11
actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb
...tion_view/renderer/partial_renderer/collection_caching.rb
+1
-1
actionview/test/template/render_test.rb
actionview/test/template/render_test.rb
+13
-4
未找到文件。
actionview/CHANGELOG.md
浏览文件 @
c90c9b2d
*
Always attach the template digest to the cache key for collection caching
even when
`virtual_path`
is not available from the view context.
Which could happen if the rendering was done directly in the controller
and not in a template.
Fixes #20535
*Roque Pinel*
*
Improve detection of partial templates eligible for collection caching,
now allowing multi-line comments at the beginning of the template file.
...
...
actionview/lib/action_view/helpers/cache_helper.rb
浏览文件 @
c90c9b2d
...
...
@@ -137,7 +137,7 @@ module CacheHelper
# The automatic cache multi read can be turned off like so:
#
# <%= render @notifications, cache: false %>
def
cache
(
name
=
{},
options
=
nil
,
&
block
)
def
cache
(
name
=
{},
options
=
{}
,
&
block
)
if
controller
.
respond_to?
(
:perform_caching
)
&&
controller
.
perform_caching
safe_concat
(
fragment_for
(
cache_fragment_name
(
name
,
options
),
options
,
&
block
))
else
...
...
@@ -153,7 +153,7 @@ def cache(name = {}, options = nil, &block)
# <b>All the topics on this project</b>
# <%= render project.topics %>
# <% end %>
def
cache_if
(
condition
,
name
=
{},
options
=
nil
,
&
block
)
def
cache_if
(
condition
,
name
=
{},
options
=
{}
,
&
block
)
if
condition
cache
(
name
,
options
,
&
block
)
else
...
...
@@ -169,22 +169,23 @@ def cache_if(condition, name = {}, options = nil, &block)
# <b>All the topics on this project</b>
# <%= render project.topics %>
# <% end %>
def
cache_unless
(
condition
,
name
=
{},
options
=
nil
,
&
block
)
def
cache_unless
(
condition
,
name
=
{},
options
=
{}
,
&
block
)
cache_if
!
condition
,
name
,
options
,
&
block
end
# This helper returns the name of a cache key for a given fragment cache
# call. By supplying
skip_digest:
true to cache, the digestion of cache
# call. By supplying
+skip_digest:+
true to cache, the digestion of cache
# fragments can be manually bypassed. This is useful when cache fragments
# cannot be manually expired unless you know the exact key which is the
# case when using memcached.
def
cache_fragment_name
(
name
=
{},
options
=
nil
)
skip_digest
=
options
&&
options
[
:skip_digest
]
#
# The digest will be generated using +virtual_path:+ if it is provided.
#
def
cache_fragment_name
(
name
=
{},
skip_digest:
nil
,
virtual_path:
nil
)
if
skip_digest
name
else
fragment_name_with_digest
(
name
)
fragment_name_with_digest
(
name
,
virtual_path
)
end
end
...
...
@@ -198,10 +199,11 @@ def fragment_cache_key(key)
private
def
fragment_name_with_digest
(
name
)
#:nodoc:
if
@virtual_path
def
fragment_name_with_digest
(
name
,
virtual_path
)
#:nodoc:
virtual_path
||=
@virtual_path
if
virtual_path
names
=
Array
(
name
.
is_a?
(
Hash
)
?
controller
.
url_for
(
name
).
split
(
"://"
).
last
:
name
)
digest
=
Digestor
.
digest
name:
@
virtual_path
,
finder:
lookup_context
,
dependencies:
view_cache_dependencies
digest
=
Digestor
.
digest
name:
virtual_path
,
finder:
lookup_context
,
dependencies:
view_cache_dependencies
[
*
names
,
digest
]
else
...
...
actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb
浏览文件 @
c90c9b2d
...
...
@@ -51,7 +51,7 @@ def collection_by_cache_keys
end
def
expanded_cache_key
(
key
)
key
=
@view
.
fragment_cache_key
(
@view
.
cache_fragment_name
(
key
))
key
=
@view
.
fragment_cache_key
(
@view
.
cache_fragment_name
(
key
,
virtual_path:
@template
.
virtual_path
))
key
.
frozen?
?
key
.
dup
:
key
# #read_multi & #write may require mutability, Dalli 2.6.0.
end
...
...
actionview/test/template/render_test.rb
浏览文件 @
c90c9b2d
...
...
@@ -7,7 +7,10 @@ class TestController < ActionController::Base
module
RenderTestCases
def
setup_view
(
paths
)
@assigns
=
{
:secret
=>
'in the sauce'
}
@view
=
ActionView
::
Base
.
new
(
paths
,
@assigns
)
@view
=
Class
.
new
(
ActionView
::
Base
)
do
def
view_cache_dependencies
;
end
end
.
new
(
paths
,
@assigns
)
@controller_view
=
TestController
.
new
.
view_context
# Reload and register danish language for testing
...
...
@@ -616,7 +619,7 @@ class CachedCustomer < Customer; end
test
"with custom key"
do
customer
=
Customer
.
new
(
"david"
)
key
=
ActionController
::
Base
.
new
.
fragment_cache_key
([
customer
,
'key'
]
)
key
=
cache_key
([
customer
,
'key'
],
"test/_customer"
)
ActionView
::
PartialRenderer
.
collection_cache
.
write
(
key
,
'Hello'
)
...
...
@@ -626,7 +629,7 @@ class CachedCustomer < Customer; end
test
"automatic caching with inferred cache name"
do
customer
=
CachedCustomer
.
new
(
"david"
)
key
=
ActionController
::
Base
.
new
.
fragment_cache_key
(
customer
)
key
=
cache_key
(
customer
,
"test/_cached_customer"
)
ActionView
::
PartialRenderer
.
collection_cache
.
write
(
key
,
'Cached'
)
...
...
@@ -636,11 +639,17 @@ class CachedCustomer < Customer; end
test
"automatic caching with as name"
do
customer
=
CachedCustomer
.
new
(
"david"
)
key
=
ActionController
::
Base
.
new
.
fragment_cache_key
(
customer
)
key
=
cache_key
(
customer
,
"test/_cached_customer_as"
)
ActionView
::
PartialRenderer
.
collection_cache
.
write
(
key
,
'Cached'
)
assert_equal
"Cached"
,
@view
.
render
(
partial:
"test/cached_customer_as"
,
collection:
[
customer
],
as: :buyer
)
end
private
def
cache_key
(
names
,
virtual_path
)
digest
=
ActionView
::
Digestor
.
digest
name:
virtual_path
,
finder:
@view
.
lookup_context
,
dependencies:
[]
@view
.
fragment_cache_key
([
*
Array
(
names
),
digest
])
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录