Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
ff29606c
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,发现更多精彩内容 >>
提交
ff29606c
编写于
3月 04, 2010
作者:
C
Carlhuda
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor cache_store to use ActionController config
上级
c8e1cc86
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
33 addition
and
30 deletion
+33
-30
actionpack/lib/action_controller/caching.rb
actionpack/lib/action_controller/caching.rb
+18
-16
actionpack/lib/action_controller/metal/compatibility.rb
actionpack/lib/action_controller/metal/compatibility.rb
+0
-5
actionpack/test/controller/caching_test.rb
actionpack/test/controller/caching_test.rb
+14
-7
actionpack/test/controller/log_subscriber_test.rb
actionpack/test/controller/log_subscriber_test.rb
+1
-2
未找到文件。
actionpack/lib/action_controller/caching.rb
浏览文件 @
ff29606c
...
...
@@ -40,15 +40,27 @@ module Caching
autoload
:Sweeping
,
'action_controller/caching/sweeping'
end
included
do
@@cache_store
=
nil
cattr_reader
:cache_store
module
ConfigMethods
def
cache_store
config
.
cache_store
end
# Defines the storage option for cached fragments
def
self
.
cache_store
=
(
store_option
)
@@cache_store
=
ActiveSupport
::
Cache
.
lookup_store
(
store_option
)
def
cache_store
=
(
store
)
config
.
cache_store
=
ActiveSupport
::
Cache
.
lookup_store
(
store
)
end
private
def
cache_configured?
perform_caching
&&
cache_store
end
end
include
ConfigMethods
included
do
extend
ConfigMethods
include
Pages
,
Actions
,
Fragments
include
Sweeping
if
defined?
(
ActiveRecord
)
...
...
@@ -56,11 +68,6 @@ def self.cache_store=(store_option)
cattr_accessor
:perform_caching
end
module
ClassMethods
def
cache_configured?
perform_caching
&&
cache_store
end
end
def
caching_allowed?
request
.
get?
&&
response
.
status
==
200
...
...
@@ -75,10 +82,5 @@ def cache(key, options = {}, &block)
yield
end
end
private
def
cache_configured?
self
.
class
.
cache_configured?
end
end
end
actionpack/lib/action_controller/metal/compatibility.rb
浏览文件 @
ff29606c
...
...
@@ -35,11 +35,6 @@ def rescue_action(env)
raise
env
[
"action_dispatch.rescue.exception"
]
end
# Defines the storage option for cached fragments
def
cache_store
=
(
store_option
)
@@cache_store
=
ActiveSupport
::
Cache
.
lookup_store
(
store_option
)
end
self
.
page_cache_directory
=
defined?
(
Rails
.
public_path
)
?
Rails
.
public_path
:
""
end
...
...
actionpack/test/controller/caching_test.rb
浏览文件 @
ff29606c
...
...
@@ -6,12 +6,18 @@
# Don't change '/../temp/' cavalierly or you might hose something you don't want hosed
FILE_STORE_PATH
=
File
.
join
(
File
.
dirname
(
__FILE__
),
'/../temp/'
,
CACHE_DIR
)
ActionController
::
Base
.
page_cache_directory
=
FILE_STORE_PATH
ActionController
::
Base
.
cache_store
=
:file_store
,
FILE_STORE_PATH
class
PageCachingTestController
<
ActionController
::
Base
class
CachingController
<
ActionController
::
Base
abstract!
self
.
cache_store
=
:file_store
,
FILE_STORE_PATH
end
class
PageCachingTestController
<
CachingController
caches_page
:ok
,
:no_content
,
:if
=>
Proc
.
new
{
|
c
|
!
c
.
request
.
format
.
json?
}
caches_page
:found
,
:not_found
def
ok
head
:ok
end
...
...
@@ -55,6 +61,7 @@ def setup
@response
=
ActionController
::
TestResponse
.
new
@controller
=
PageCachingTestController
.
new
@controller
.
cache_store
=
:file_store
,
FILE_STORE_PATH
@params
=
{
:controller
=>
'posts'
,
:action
=>
'index'
,
:only_path
=>
true
,
:skip_relative_url_root
=>
true
}
@rewriter
=
ActionController
::
UrlRewriter
.
new
(
@request
,
@params
)
...
...
@@ -148,7 +155,7 @@ def page_cached?(action)
end
end
class
ActionCachingTestController
<
ActionController
::
Base
class
ActionCachingTestController
<
CachingController
rescue_from
(
Exception
)
{
head
500
}
if
defined?
ActiveRecord
rescue_from
(
ActiveRecord
::
RecordNotFound
)
{
head
:not_found
}
...
...
@@ -522,7 +529,7 @@ def read_fragment(path)
end
end
class
FragmentCachingTestController
<
ActionController
::
Base
class
FragmentCachingTestController
<
CachingController
def
some_action
;
end
;
end
...
...
@@ -531,8 +538,8 @@ def setup
super
ActionController
::
Base
.
perform_caching
=
true
@store
=
ActiveSupport
::
Cache
::
MemoryStore
.
new
ActionController
::
Base
.
cache_store
=
@store
@controller
=
FragmentCachingTestController
.
new
@controller
.
cache_store
=
@store
@params
=
{
:controller
=>
'posts'
,
:action
=>
'index'
}
@request
=
ActionController
::
TestRequest
.
new
@response
=
ActionController
::
TestResponse
.
new
...
...
@@ -630,7 +637,7 @@ def test_fragment_for
end
class
FunctionalCachingController
<
ActionController
::
Base
class
FunctionalCachingController
<
CachingController
def
fragment_cached
end
...
...
@@ -664,8 +671,8 @@ def setup
super
ActionController
::
Base
.
perform_caching
=
true
@store
=
ActiveSupport
::
Cache
::
MemoryStore
.
new
ActionController
::
Base
.
cache_store
=
@store
@controller
=
FunctionalCachingController
.
new
@controller
.
cache_store
=
@store
@request
=
ActionController
::
TestRequest
.
new
@response
=
ActionController
::
TestResponse
.
new
end
...
...
actionpack/test/controller/log_subscriber_test.rb
浏览文件 @
ff29606c
...
...
@@ -46,8 +46,7 @@ def setup
@cache_path
=
File
.
expand_path
(
'../temp/test_cache'
,
File
.
dirname
(
__FILE__
))
ActionController
::
Base
.
page_cache_directory
=
@cache_path
ActionController
::
Base
.
cache_store
=
:file_store
,
@cache_path
@controller
.
cache_store
=
:file_store
,
@cache_path
Rails
::
LogSubscriber
.
add
(
:action_controller
,
ActionController
::
Railties
::
LogSubscriber
.
new
)
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录