activerecord - Rails 3.0.3 Rails.cache.read can't write to DB -
i playing around rails 3 rails.cache feature , when write activerecord entry cache, cannot read back, change attributes write database. "typeerror: can't modify frozen hash". used use memcache plugin, i'm trying switch on heroku, , it's incredibly annoying cannot save activerecord entries throw memcache. result in lot of unnecessary db reads change small bits of information.
for example, might in database. assuming user model is:
user -> login:string , typing following rails c
user = user.new user.login = 'test' user.save rails.cache.write('user:login:test', user) user2 = rails.cache.read('user:login:test') user2.login = 'test2' typeerror: can't modify frozen hash /app/.bundle/gems/ruby/1.8/gems/activerecord-3.0.3/lib/active_record/attribute_methods/write.rb:26:in `[]=' /app/.bundle/gems/ruby/1.8/gems/activerecord-3.0.3/lib/active_record/attribute_methods/write.rb:26:in `write_attribute' /app/.bundle/gems/ruby/1.8/gems/activerecord-3.0.3/lib/active_record/attribute_methods/dirty.rb:61:in `write_attribute' /app/.bundle/gems/ruby/1.8/gems/activerecord-3.0.3/lib/active_record/attribute_methods/write.rb:13:in `login=' does know how solve problem?
after getting user2 object value line:
user2 = rails.cache.read('user:login:test') do following:
dup_user = user2.dup # make clone of user2 object dup_user.login = test_2 then "frozen hash" exception should not appear again.
Comments
Post a Comment