Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
f9a8646d
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,体验更适合开发者的 AI 搜索 >>
未验证
提交
f9a8646d
编写于
2月 04, 2018
作者:
J
Jeremy Daer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Redis cache store: consolidate serialization
Use `serialize_entry` throughout and introduce `serialize_entries`.
上级
08aa8afd
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
21 addition
and
17 deletion
+21
-17
activesupport/lib/active_support/cache/redis_cache_store.rb
activesupport/lib/active_support/cache/redis_cache_store.rb
+21
-17
未找到文件。
activesupport/lib/active_support/cache/redis_cache_store.rb
浏览文件 @
f9a8646d
...
...
@@ -70,7 +70,7 @@ def read_entry(key, options)
def
write_entry
(
key
,
entry
,
options
)
if
options
[
:raw
]
&&
local_cache
raw_entry
=
Entry
.
new
(
entry
.
value
.
to_s
)
raw_entry
=
Entry
.
new
(
serialize_entry
(
entry
,
raw:
true
)
)
raw_entry
.
expires_at
=
entry
.
expires_at
super
(
key
,
raw_entry
,
options
)
else
...
...
@@ -81,7 +81,7 @@ def write_entry(key, entry, options)
def
write_multi_entries
(
entries
,
options
)
if
options
[
:raw
]
&&
local_cache
raw_entries
=
entries
.
map
do
|
key
,
entry
|
raw_entry
=
Entry
.
new
(
entry
.
value
.
to_s
)
raw_entry
=
Entry
.
new
(
serialize_entry
(
entry
,
raw:
true
)
)
raw_entry
.
expires_at
=
entry
.
expires_at
end
.
to_h
...
...
@@ -327,7 +327,7 @@ def read_multi_mget(*names)
#
# Requires Redis 2.6.12+ for extended SET options.
def
write_entry
(
key
,
entry
,
unless_exist:
false
,
raw:
false
,
expires_in:
nil
,
race_condition_ttl:
nil
,
**
options
)
value
=
raw
?
entry
.
value
.
to_s
:
serialize_entry
(
entry
)
serialized_entry
=
serialize_entry
(
entry
,
raw:
raw
)
# If race condition TTL is in use, ensure that cache entries
# stick around a bit longer after they would have expired
...
...
@@ -342,9 +342,9 @@ def write_entry(key, entry, unless_exist: false, raw: false, expires_in: nil, ra
modifiers
[
:nx
]
=
unless_exist
modifiers
[
:px
]
=
(
1000
*
expires_in
.
to_f
).
ceil
if
expires_in
redis
.
set
key
,
value
,
modifiers
redis
.
set
key
,
serialized_entry
,
modifiers
else
redis
.
set
key
,
value
redis
.
set
key
,
serialized_entry
end
end
end
...
...
@@ -361,13 +361,7 @@ def write_multi_entries(entries, expires_in: nil, **options)
if
entries
.
any?
if
mset_capable?
&&
expires_in
.
nil?
failsafe
:write_multi_entries
do
serialized_entries
=
if
options
[
:raw
]
entries
.
transform_values
{
|
e
|
e
.
value
.
to_s
}
else
entries
.
transform_values
{
|
e
|
serialize_entry
(
e
)
}
end
redis
.
mapped_mset
(
serialized_entries
)
redis
.
mapped_mset
(
serialize_entries
(
entries
,
raw:
options
[
:raw
]))
end
else
super
...
...
@@ -390,15 +384,25 @@ def truncate_key(key)
end
end
def
deserialize_entry
(
raw_value
)
if
raw_value
entry
=
Marshal
.
load
(
raw_value
)
rescue
raw_value
def
deserialize_entry
(
serialized_entry
)
if
serialized_entry
entry
=
Marshal
.
load
(
serialized_entry
)
rescue
serialized_entry
entry
.
is_a?
(
Entry
)
?
entry
:
Entry
.
new
(
entry
)
end
end
def
serialize_entry
(
entry
)
Marshal
.
dump
(
entry
)
def
serialize_entry
(
entry
,
raw:
false
)
if
raw
entry
.
value
.
to_s
else
Marshal
.
dump
(
entry
)
end
end
def
serialize_entries
(
entries
,
raw:
false
)
entries
.
transform_values
do
|
entry
|
serialize_entry
entry
,
raw:
raw
end
end
def
failsafe
(
method
,
returning:
nil
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录