I am working on a Rails 4 project and using readthis_store gem to do my caching. I do have the following code though
I have user model with a method block_reason
class User < ActiveRecord::Base
def block_reason
Rails.cache.fetch([self.cache_key, __method__], expires_in: 1.hours) do
{
blocked: true,
blocked_reason: reason,
blocked_reason_text: reason_text,
application_blocks: {
status: self..status,
name_check: self.name_check,
id_check: self.id_check,
}
}
end
end
end
In my controller, i have the following method index which calls the block_reason method
class Private::V1::JobsController < Private::V1::ApiController
def index
response = @current_user.block_reason.try(:to_h)
json_success(nil, response)
end
end
But when i make the APi call, i get the error
TypeError: singleton can't be dumped
from readthis/entity.rb:50:in `dump'
from readthis/entity.rb:50:in `dump'
from readthis/cache.rb:315:in `write_entity'
from readthis/cache.rb:86:in `block in write'
from connection_pool.rb:63:in `block (2 levels) in with'
from connection_pool.rb:62:in `handle_interrupt'
from connection_pool.rb:62:in `block in with'
from connection_pool.rb:59:in `handle_interrupt'
from connection_pool.rb:59:in `with'
from readthis/cache.rb:346:in `block in invoke'
from readthis/cache.rb:338:in `block in instrument'
from active_support/notifications.rb:166:in `instrument'
from readthis/cache.rb:338:in `instrument'
from readthis/cache.rb:345:in `invoke'
from readthis/cache.rb:85:in `write'
from readthis/cache.rb:146:in `fetch'
I know the error is happening in the readthis_store gem and has something to do with Marshal.dump defining the object cached as a singleton.
But i do not know how else to solve this issue. I have tried various options but all to no avail.
Not sure if anyone has come across this and been able to solve it on Rails 4.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…