Remove conversion code for old Rails cache entry

This code was there just to convert entries generated in Rails
4.0.0.beta1 applications to a supported format.

It is almost unlikely that any existent application have this cache
entry format in their caches at the point that Rails 5 will be released
so we don't need this code anymore.
This commit is contained in:
Rafael Mendonça França 2015-01-01 22:31:27 -03:00
parent ddd0a22133
commit 41d72ce372
2 changed files with 0 additions and 50 deletions

View File

@ -615,14 +615,12 @@ module ActiveSupport
end
def value
convert_version_4beta1_entry! if defined?(@v)
compressed? ? uncompress(@value) : @value
end
# Check if the entry is expired. The +expires_in+ parameter can override
# the value set when the entry was created.
def expired?
convert_version_4beta1_entry! if defined?(@v)
@expires_in && @created_at + @expires_in <= Time.now.to_f
end
@ -658,8 +656,6 @@ module ActiveSupport
# Duplicate the value in a class. This is used by cache implementations that don't natively
# 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
@ -692,26 +688,6 @@ module ActiveSupport
def uncompress(value)
Marshal.load(Zlib::Inflate.inflate(value))
end
# The internals of this method changed between Rails 3.x and 4.0. This method provides the glue
# to ensure that cache entries created under the old version still work with the new class definition.
def convert_version_4beta1_entry!
if defined?(@v)
@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
remove_instance_variable(:@x)
end
end
end
end
end

View File

@ -1047,30 +1047,4 @@ class CacheEntryTest < ActiveSupport::TestCase
assert_equal value, entry.value
assert_equal value.bytesize, entry.size
end
def test_restoring_version_4beta1_entries
version_4beta1_entry = ActiveSupport::Cache::Entry.allocate
version_4beta1_entry.instance_variable_set(:@v, "hello")
version_4beta1_entry.instance_variable_set(:@x, Time.now.to_i + 60)
entry = Marshal.load(Marshal.dump(version_4beta1_entry))
assert_equal "hello", entry.value
assert_equal false, entry.expired?
end
def test_restoring_compressed_version_4beta1_entries
version_4beta1_entry = ActiveSupport::Cache::Entry.allocate
version_4beta1_entry.instance_variable_set(:@v, Zlib::Deflate.deflate(Marshal.dump("hello")))
version_4beta1_entry.instance_variable_set(:@c, true)
entry = Marshal.load(Marshal.dump(version_4beta1_entry))
assert_equal "hello", entry.value
end
def test_restoring_expired_version_4beta1_entries
version_4beta1_entry = ActiveSupport::Cache::Entry.allocate
version_4beta1_entry.instance_variable_set(:@v, "hello")
version_4beta1_entry.instance_variable_set(:@x, Time.now.to_i - 1)
entry = Marshal.load(Marshal.dump(version_4beta1_entry))
assert_equal true, entry.expired?
assert_equal "hello", entry.value
end
end