Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
a263f377
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 搜索 >>
提交
a263f377
编写于
7月 29, 2011
作者:
B
Brian Durand
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Change ActiveSupport::Cache behavior to always return duplicate objects instead of frozen objects.
上级
caacf856
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
18 addition
and
22 deletion
+18
-22
activesupport/lib/active_support/cache.rb
activesupport/lib/active_support/cache.rb
+8
-15
activesupport/test/caching_test.rb
activesupport/test/caching_test.rb
+10
-7
未找到文件。
activesupport/lib/active_support/cache.rb
浏览文件 @
a263f377
...
...
@@ -557,15 +557,14 @@ def initialize(value, options = {})
@expires_in
=
options
[
:expires_in
]
@expires_in
=
@expires_in
.
to_f
if
@expires_in
@created_at
=
Time
.
now
.
to_f
if
defined?
(
value
)
if
value
.
nil?
@value
=
nil
else
@value
=
Marshal
.
dump
(
value
)
if
should_compress?
(
value
,
options
)
@value
=
Zlib
::
Deflate
.
deflate
(
Marshal
.
dump
(
value
)
)
@value
=
Zlib
::
Deflate
.
deflate
(
@value
)
@compressed
=
true
else
@value
=
value
end
else
@value
=
nil
end
end
...
...
@@ -576,12 +575,8 @@ def raw_value
# Get the value stored in the cache.
def
value
if
defined?
(
@value
)
val
=
compressed?
?
Marshal
.
load
(
Zlib
::
Inflate
.
inflate
(
@value
))
:
@value
unless
val
.
frozen?
val
.
freeze
rescue
nil
end
val
if
@value
Marshal
.
load
(
compressed?
?
Zlib
::
Inflate
.
inflate
(
@value
)
:
@value
)
end
end
...
...
@@ -614,10 +609,8 @@ def expires_at
def
size
if
@value
.
nil?
0
elsif
@value
.
respond_to?
(
:bytesize
)
@value
.
bytesize
else
Marshal
.
dump
(
@value
)
.
bytesize
@value
.
bytesize
end
end
...
...
activesupport/test/caching_test.rb
浏览文件 @
a263f377
...
...
@@ -204,7 +204,7 @@ def test_read_and_write_compressed_small_data
@cache
.
write
(
'foo'
,
'bar'
,
:compress
=>
true
)
raw_value
=
@cache
.
send
(
:read_entry
,
'foo'
,
{}).
raw_value
assert_equal
'bar'
,
@cache
.
read
(
'foo'
)
assert_equal
'bar'
,
raw_value
assert_equal
'bar'
,
Marshal
.
load
(
raw_value
)
end
def
test_read_and_write_compressed_large_data
...
...
@@ -270,10 +270,12 @@ def test_delete
assert
!
@cache
.
exist?
(
'foo'
)
end
def
test_
store_objects_should_be_immutable
def
test_
read_should_return_a_different_object_id_each_time_it_is_called
@cache
.
write
(
'foo'
,
'bar'
)
assert_raise
(
ActiveSupport
::
FrozenObjectError
)
{
@cache
.
read
(
'foo'
).
gsub!
(
/.*/
,
'baz'
)
}
assert_equal
'bar'
,
@cache
.
read
(
'foo'
)
assert_not_equal
@cache
.
read
(
'foo'
).
object_id
,
@cache
.
read
(
'foo'
).
object_id
value
=
@cache
.
read
(
'foo'
)
value
<<
'bingo'
assert_not_equal
value
,
@cache
.
read
(
'foo'
)
end
def
test_original_store_objects_should_not_be_immutable
...
...
@@ -551,7 +553,8 @@ def test_key_transformation_with_pathname
class
MemoryStoreTest
<
ActiveSupport
::
TestCase
def
setup
@cache
=
ActiveSupport
::
Cache
.
lookup_store
(
:memory_store
,
:expires_in
=>
60
,
:size
=>
100
)
@record_size
=
Marshal
.
dump
(
"aaaaaaaaaa"
).
bytesize
@cache
=
ActiveSupport
::
Cache
.
lookup_store
(
:memory_store
,
:expires_in
=>
60
,
:size
=>
@record_size
*
10
)
end
include
CacheStoreBehavior
...
...
@@ -566,7 +569,7 @@ def test_prune_size
@cache
.
write
(
5
,
"eeeeeeeeee"
)
&&
sleep
(
0.001
)
@cache
.
read
(
2
)
&&
sleep
(
0.001
)
@cache
.
read
(
4
)
@cache
.
prune
(
30
)
@cache
.
prune
(
@record_size
*
3
)
assert_equal
true
,
@cache
.
exist?
(
5
)
assert_equal
true
,
@cache
.
exist?
(
4
)
assert_equal
false
,
@cache
.
exist?
(
3
)
...
...
@@ -719,7 +722,7 @@ def test_compress_values
def
test_non_compress_values
entry
=
ActiveSupport
::
Cache
::
Entry
.
new
(
"value"
)
assert_equal
"value"
,
entry
.
value
assert_equal
"value"
,
entry
.
raw_value
assert_equal
"value"
,
Marshal
.
load
(
entry
.
raw_value
)
assert_equal
false
,
entry
.
compressed?
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录