0

我发现保存记录后查询缓存被清除。有人知道有什么问题吗?请查看以下代码。

ActiveRecord::Base.cache do 
  policy_file = FormUnit.find_by_number("F.XXX")

  # @query_cache has a value that is a query of policy_file
  pp ActiveRecord::Base.connection.instance_variable_get("@query_cache")

  # fetched it from cache
  FormUnit.find_by_number("F.XXX")

  policy_file_branch = policy_file.forms.build(edition: "10/10", effective_date: "2013/1/1")

  # still can fetch it from cache query.
  pp ActiveRecord::Base.connection.instance_variable_get("@query_cache")
  FormUnit.find_by_number("F.XXX")


  policy_file_branch.save

  # now, @query_cache was empty and had to fetch it in sql query.
  pp ActiveRecord::Base.connection.instance_variable_get("@query_cache")
  FormUnit.find_by_number("F.XXX")

end
4

0 回答 0