Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
66df3662
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,发现更多精彩内容 >>
提交
66df3662
编写于
4月 11, 2018
作者:
G
Godfrey Chan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix `ActiveSupport::Cache` compression
(See previous commit for a description of the issue)
上级
84b1feea
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
60 addition
and
37 deletion
+60
-37
activesupport/CHANGELOG.md
activesupport/CHANGELOG.md
+7
-0
activesupport/lib/active_support/cache.rb
activesupport/lib/active_support/cache.rb
+32
-35
activesupport/test/cache/behaviors/cache_store_behavior.rb
activesupport/test/cache/behaviors/cache_store_behavior.rb
+21
-2
未找到文件。
activesupport/CHANGELOG.md
浏览文件 @
66df3662
*
Fix bug where
`ActiveSupport::Cache`
will massively inflate the storage
size when compression is enabled (which is true by default). This patch
does not attempt to repair existing data: please manually flush the cache
to clear out the problematic entries.
*Godfrey Chan*
*
Fix bug where
`URI.unscape`
would fail with mixed Unicode/escaped character input:
URI.unescape("\xe3\x83\x90") # => "バ"
...
...
activesupport/lib/active_support/cache.rb
浏览文件 @
66df3662
...
...
@@ -712,17 +712,14 @@ class Entry # :nodoc:
DEFAULT_COMPRESS_LIMIT
=
1
.
kilobyte
# Creates a new cache entry for the specified value. Options supported are
# +:compress+, +:compress_threshold+, and +:expires_in+.
def
initialize
(
value
,
options
=
{})
@value
=
value
if
should_compress?
(
options
)
compress!
end
@version
=
options
[
:version
]
# +:compress+, +:compress_threshold+, +:version+ and +:expires_in+.
def
initialize
(
value
,
compress:
true
,
compress_threshold:
DEFAULT_COMPRESS_LIMIT
,
version:
nil
,
expires_in:
nil
,
**
)
@value
=
value
@version
=
version
@created_at
=
Time
.
now
.
to_f
@expires_in
=
options
[
:expires_in
]
@expires_in
=
@expires_in
.
to_f
if
@expires_in
@expires_in
=
expires_in
&&
expires_in
.
to_f
compress!
(
compress_threshold
)
if
compress
end
def
value
...
...
@@ -754,17 +751,13 @@ def expires_at=(value)
# Returns the size of the cached value. This could be less than
# <tt>value.size</tt> if the data is compressed.
def
size
if
defined?
(
@s
)
@s
case
value
when
NilClass
0
when
String
@value
.
bytesize
else
case
value
when
NilClass
0
when
String
@value
.
bytesize
else
@s
=
Marshal
.
dump
(
@value
).
bytesize
end
@s
||=
Marshal
.
dump
(
@value
).
bytesize
end
end
...
...
@@ -781,31 +774,35 @@ def dup_value!
end
private
def
should_compress?
(
options
)
if
@value
&&
options
.
fetch
(
:compress
,
true
)
compress_threshold
=
options
.
fetch
(
:compress_threshold
,
DEFAULT_COMPRESS_LIMIT
)
serialized_value_size
=
(
@value
.
is_a?
(
String
)
?
@value
:
marshaled_value
).
bytesize
def
compress!
(
compress_threshold
)
case
@value
when
nil
,
true
,
false
,
Numeric
uncompressed_size
=
0
when
String
uncompressed_size
=
@value
.
bytesize
else
serialized
=
Marshal
.
dump
(
@value
)
uncompressed_size
=
serialized
.
bytesize
end
if
uncompressed_size
>=
compress_threshold
serialized
||=
Marshal
.
dump
(
@value
)
compressed
=
Zlib
::
Deflate
.
deflate
(
serialized
)
serialized_value_size
>=
compress_threshold
if
compressed
.
bytesize
<
uncompressed_size
@value
=
compressed
@compressed
=
true
end
end
end
def
compressed?
defined?
(
@compressed
)
?
@compressed
:
false
end
def
compress!
@value
=
Zlib
::
Deflate
.
deflate
(
marshaled_value
)
@compressed
=
true
defined?
(
@compressed
)
end
def
uncompress
(
value
)
Marshal
.
load
(
Zlib
::
Inflate
.
inflate
(
value
))
end
def
marshaled_value
@marshaled_value
||=
Marshal
.
dump
(
@value
)
end
end
end
end
activesupport/test/cache/behaviors/cache_store_behavior.rb
浏览文件 @
66df3662
...
...
@@ -162,7 +162,7 @@ def test_nil_with_compress_false
end
def
test_nil_with_compress_low_compress_threshold
assert_uncompressed
(
nil
,
compress:
true
,
compress_threshold:
2
)
assert_uncompressed
(
nil
,
compress:
true
,
compress_threshold:
1
)
end
def
test_small_string_with_default_compression_settings
...
...
@@ -178,7 +178,7 @@ def test_small_string_with_compress_false
end
def
test_small_string_with_low_compress_threshold
assert_compressed
(
SMALL_STRING
,
compress:
true
,
compress_threshold:
2
)
assert_compressed
(
SMALL_STRING
,
compress:
true
,
compress_threshold:
1
)
end
def
test_small_object_with_default_compression_settings
...
...
@@ -229,6 +229,25 @@ def test_large_object_with_high_compress_threshold
assert_uncompressed
(
LARGE_OBJECT
,
compress:
true
,
compress_threshold:
1
.
megabyte
)
end
def
test_incompressable_data
assert_uncompressed
(
nil
,
compress:
true
,
compress_threshold:
1
)
assert_uncompressed
(
true
,
compress:
true
,
compress_threshold:
1
)
assert_uncompressed
(
false
,
compress:
true
,
compress_threshold:
1
)
assert_uncompressed
(
0
,
compress:
true
,
compress_threshold:
1
)
assert_uncompressed
(
1.2345
,
compress:
true
,
compress_threshold:
1
)
assert_uncompressed
(
""
,
compress:
true
,
compress_threshold:
1
)
incompressible
=
nil
# generate an incompressible string
loop
do
incompressible
=
SecureRandom
.
bytes
(
1
.
kilobyte
)
break
if
incompressible
.
bytesize
<
Zlib
::
Deflate
.
deflate
(
incompressible
).
bytesize
end
assert_uncompressed
(
incompressible
,
compress:
true
,
compress_threshold:
1
)
end
def
test_cache_key
obj
=
Object
.
new
def
obj
.
cache_key
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录