Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
1c35f933
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,发现更多精彩内容 >>
提交
1c35f933
编写于
11月 03, 2013
作者:
D
David Heinemeier Hansson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Aesthetics
上级
50b7d21e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
30 addition
and
22 deletion
+30
-22
activesupport/lib/active_support/cache.rb
activesupport/lib/active_support/cache.rb
+30
-22
未找到文件。
activesupport/lib/active_support/cache.rb
浏览文件 @
1c35f933
...
...
@@ -12,10 +12,10 @@
module
ActiveSupport
# See ActiveSupport::Cache::Store for documentation.
module
Cache
autoload
:FileStore
,
'active_support/cache/file_store'
autoload
:MemoryStore
,
'active_support/cache/memory_store'
autoload
:FileStore
,
'active_support/cache/file_store'
autoload
:MemoryStore
,
'active_support/cache/memory_store'
autoload
:MemCacheStore
,
'active_support/cache/mem_cache_store'
autoload
:NullStore
,
'active_support/cache/null_store'
autoload
:NullStore
,
'active_support/cache/null_store'
# These options mean something to all cache implementations. Individual cache
# implementations may support additional options.
...
...
@@ -88,25 +88,24 @@ def expand_cache_key(key, namespace = nil)
end
private
def
retrieve_cache_key
(
key
)
case
when
key
.
respond_to?
(
:cache_key
)
then
key
.
cache_key
when
key
.
is_a?
(
Array
)
then
key
.
map
{
|
element
|
retrieve_cache_key
(
element
)
}.
to_param
when
key
.
respond_to?
(
:to_a
)
then
retrieve_cache_key
(
key
.
to_a
)
else
key
.
to_param
end
.
to_s
end
def
retrieve_cache_key
(
key
)
case
when
key
.
respond_to?
(
:cache_key
)
then
key
.
cache_key
when
key
.
is_a?
(
Array
)
then
key
.
map
{
|
element
|
retrieve_cache_key
(
element
)
}.
to_param
when
key
.
respond_to?
(
:to_a
)
then
retrieve_cache_key
(
key
.
to_a
)
else
key
.
to_param
end
.
to_s
end
# Obtains the specified cache store class, given the name of the +store+.
# Raises an error when the store class cannot be found.
def
retrieve_store_class
(
store
)
require
"active_support/cache/
#{
store
}
"
rescue
LoadError
=>
e
raise
"Could not find cache store adapter for
#{
store
}
(
#{
e
}
)"
else
ActiveSupport
::
Cache
.
const_get
(
store
.
to_s
.
camelize
)
end
# Obtains the specified cache store class, given the name of the +store+.
# Raises an error when the store class cannot be found.
def
retrieve_store_class
(
store
)
require
"active_support/cache/
#{
store
}
"
rescue
LoadError
=>
e
raise
"Could not find cache store adapter for
#{
store
}
(
#{
e
}
)"
else
ActiveSupport
::
Cache
.
const_get
(
store
.
to_s
.
camelize
)
end
end
# An abstract cache store class. There are multiple cache store
...
...
@@ -153,7 +152,6 @@ def retrieve_store_class(store)
# or +write+. To specify the threshold at which to compress values, set the
# <tt>:compress_threshold</tt> option. The default threshold is 16K.
class
Store
cattr_accessor
:logger
,
:instance_writer
=>
true
attr_reader
:silence
,
:options
...
...
@@ -385,6 +383,7 @@ def fetch_multi(*names)
# Options are passed to the underlying cache implementation.
def
write
(
name
,
value
,
options
=
nil
)
options
=
merged_options
(
options
)
instrument
(
:write
,
name
,
options
)
do
entry
=
Entry
.
new
(
value
,
options
)
write_entry
(
namespaced_key
(
name
,
options
),
entry
,
options
)
...
...
@@ -396,6 +395,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
delete_entry
(
namespaced_key
(
name
,
options
),
options
)
end
...
...
@@ -406,6 +406,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
entry
=
read_entry
(
namespaced_key
(
name
,
options
),
options
)
(
entry
&&
!
entry
.
expired?
)
||
false
...
...
@@ -585,6 +586,7 @@ def save_block_result_to_cache(name, options)
result
=
instrument
(
:generate
,
name
,
options
)
do
|
payload
|
yield
(
name
)
end
write
(
name
,
result
,
options
)
result
end
...
...
@@ -608,6 +610,7 @@ def initialize(value, options = {})
else
@value
=
value
end
@created_at
=
Time
.
now
.
to_f
@expires_in
=
options
[
:expires_in
]
@expires_in
=
@expires_in
.
to_f
if
@expires_in
...
...
@@ -658,6 +661,7 @@ def size
# serialize entries to protect against accidental cache modifications.
def
dup_value!
convert_version_4beta1_entry!
if
defined?
(
@v
)
if
@value
&&
!
compressed?
&&
!
(
@value
.
is_a?
(
Numeric
)
||
@value
==
true
||
@value
==
false
)
if
@value
.
is_a?
(
String
)
@value
=
@value
.
dup
...
...
@@ -672,8 +676,10 @@ def should_compress?(value, options)
if
value
&&
options
[
:compress
]
compress_threshold
=
options
[
:compress_threshold
]
||
DEFAULT_COMPRESS_LIMIT
serialized_value_size
=
(
value
.
is_a?
(
String
)
?
value
:
Marshal
.
dump
(
value
)).
bytesize
return
true
if
serialized_value_size
>=
compress_threshold
end
false
end
...
...
@@ -696,10 +702,12 @@ def convert_version_4beta1_entry!
@value
=
@v
remove_instance_variable
(
:@v
)
end
if
defined?
(
@c
)
@compressed
=
@c
remove_instance_variable
(
:@c
)
end
if
defined?
(
@x
)
&&
@x
@created_at
||=
Time
.
now
.
to_f
@expires_in
=
@x
-
@created_at
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录