【发布时间】:2013-10-14 15:25:42
【问题描述】:
在同一应用程序中使用 identity_cache (v 0.0.4) 和延迟作业 (v 3.0.3) 时,我收到错误“#<0x007f9836dfdab0>0x007f9836dfdab0>
标签: ruby ruby-on-rails-3 yaml delayed-job
在同一应用程序中使用 identity_cache (v 0.0.4) 和延迟作业 (v 3.0.3) 时,我收到错误“#<0x007f9836dfdab0>0x007f9836dfdab0>
标签: ruby ruby-on-rails-3 yaml delayed-job
也许不是最优雅的解决方案,但下面的猴子补丁是一种解决方法。到目前为止,我还没有观察到任何错误。我把它放在 .../config/initializers/patch_identity_cache.rb:
module IdentityCache
module ConfigurationDSL
extend ActiveSupport::Concern
module ClassMethods
alias_method :original_build_normalized_has_many_cache, :build_normalized_has_many_cache
def build_normalized_has_many_cache(association, options)
original_build_normalized_has_many_cache(association, options)
self.class_eval(ruby = <<-CODE, __FILE__, __LINE__)
def #{options[:population_method_name]}
@#{options[:ids_variable_name]} = #{options[:ids_name]}
association_cache.delete(:#{association})
@#{options[:records_variable_name]} = nil
end
CODE
end
end
end
end
【讨论】:
pduey 的回答对我不起作用,因为自他回答以来 IdentityCache 代码发生了变化。
this issue 的以下修复适用于 identity_cache 0.2.3:
# config/initializers/patch_identity_cache.rb:
ActiveRecord::Base.class_eval do
def encode_with_override_override(coder)
encode_with_without_override(coder)
coder.tag = "!ruby/ActiveRecord:#{self.class.name}" unless coder.is_a? ::Hash
end
alias_method :encode_with, :encode_with_override_override
end
【讨论】: