rails/rails — Issue #3526: Rails.cache.read unmarshal everything as string
Author: drjoke
Created: 2011-11-05 05:27:08+00:00
State: open

This problem prevents me from using Rails.cache to store objects other than string. This used to work fine with Ruby 1.8 and Rails 2.3. However, with my new setup migrating to Ruby 1.9.2 or 1.9.3 and Rails 3.1.1 I now get this problem.

Please also note that Rails.cache is using memcache in the backend.

drjoke-7:atcloud.com atip$ /opt/ruby-1.9.2/bin/rails console

Loading development environment (Rails 3.1.1)

irb(main):001:0> user = User.find 1
User Load (0.5ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
=> #
irb(main):002:0> Rails.cache.write "test", user
=> true

irb(main):003:0> test = Rails.cache.read "test"
=> "\x04\bo: ActiveSupport::Cache::Entry\t:\x10@compressedF:\x10@expires_in0:\x10@created_atf\x1A1320470467.1405299\x00\xFEq:\v@valueo:\tUser\x10:\x10@attributes{&I\"\aid\x06:\x06ETi\x06I\"\rnickname\x06;\fTI\"\x1D\xE0\xB8\x88\xE0\xB8\xAD\xE0\xB8\xA1\xE0\xB8\xA2\xE0\xB8\xB8\xE0\xB8\x97\xE0\xB8\x98\xE0\xB9\x8C\x06;\fTI\"\rusername\x06;\fTI\"\fjomyoot\x06;\fTI\"\x0Fcreated_at\x06;\fT0I\"\x0Fupdated_at\x06;\fTIu:\tTime\r\xCD\xE3\e\xC0\x00\x00\xD0]\x06:\v@_zone\"\bUTCI\"\x0Eactive_at\x06;\fTIu;\r\r\xCD\xE3\e\xC0\x00\x00\xD0]\x06;\x0E\"\bUTCI\"\x13homepage_views\x06;\fTi\x03b\xAD\x02I\"\nscore\x06;\fTi\x02\xD2\x16I\"\nlevel\x06;\fTi\rI\"\nstars\x06;\fTi\vI\"\x1Aremaining_story_votes\x06;\fTi\rI\"\"remaining_story_comment_votes\x06;\fTi\x15I\"\x14remaining_stars\x06;\fTi\x06I\"\elatest_tweeter_content\x06;\fTI\"\nasdde\x06;\fTI\"\x1Eremaining_comment_bonuses\x06;\fTi\nI\"\x1Eremaining_tweeter_bonuses\x06;\fTi\x06I\"\x0Elatest_ip\x06;\fT0I\"\x11user_role_id\x06;\fTi\x06I\"\x14image_file_name\x06;\fTI\"-Screen shot 2011-07-20 at 9.19.11 PM.png\x06;\fTI\"\x17image_content_type\x06;\fTI\"\x0Eimage/png\x06;\fTI\"\x14image_file_size\x06;\fTi\x03\x17\x97\x03I\"\fsite_id\x06;\fTi\x06I\"\x0Faccount_id\x06;\fTi\x06I\"\x0Eis_hidden\x06;\fTi\x00I\"\eimage_upload_status_id\x06;\fTi\bI\"\x12facebook_link\x06;\fTI\";http://www.facebook.com/profile.php?id=100000953928897\x06;\fTI\"\x17facebook_image_url\x06;\fTI\"\x00\x06;\fTI\"\x12entries_count\x06;\fTi\x02\x91\x03I\"\x14followers_count\x06;\fTi\x0FI\"\bage\x06;\fT0I\"\x0Egender_id\x06;\fTi\bI\"\x10province_id\x06;\fTi\x06I\"*belongs_to_manually_selected_province\x06;\fTi\x00:\x0E@relation0:\x18@changed_attributes{\x00:\x18@previously_changed{\x00:\x16@attributes_cache{\bI\"\x0Fcreated_at\x06;\fF0I\"\x0Fupdated_at\x06;\fFU: ActiveSupport::TimeWithZone[\b@\x11I\"\fBangkok\x06;\fTIu;\r\r\xD4\xE3\e\xC0\x00\x00\xD0]\x06;\x0E\"\bUTCI\"\x0Eactive_at\x06;\fFU;\x13[\b@\x14@ test.class
=> String