无法转储 TypeError 单例

问题描述

我正在处理 Rails 4 项目并使用 readthis_store gem 进行缓存。我确实有以下代码

我有一个带有方法 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

在我的控制器中,我有以下调用 block_reason 方法方法索引

class Private::V1::JobsController < Private::V1::ApiController
  def index
    response = @current_user.block_reason.try(:to_h)

    json_success(nil,response)
  end
end

但是当我进行 API 调用时,我收到错误

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'

我知道错误发生在 readthis_store gem 中,并且与 Marshal.dump 定义缓存为单例的对象有关。

但我不知道如何解决这个问题。我尝试了各种选择,但都无济于事。

不确定是否有人遇到过这个问题并且能够在 Rails 4 上解决它。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)