【问题标题】:Action caching is not re-using large cached fragments动作缓存不会重复使用大的缓存片段
【发布时间】:2013-03-10 14:58:20
【问题描述】:

我正在尝试在我的 Policy 控制器上实现动作缓存,但是,当呈现的片段大小增加时,它不会重新使用缓存的片段。

当我的操作“索引”仅显示 10 个 JSON 对象时,它会正确创建和读取操作的片段。 证明人:

Started GET "/policies" for 127.0.0.1 at 2013-03-10 01:03:38 -0500
Processing by PolicyController#index as JSON
Read fragment views/railsdev.com:3000/policies.json (0.3ms)
  VideoPolicy Load (0.4ms)  SELECT `video_policies`.* FROM `video_policies` 
Write fragment views/railsdev.com:3000/policies.json (0.5ms)
Completed 200 OK in 27ms (Views: 0.2ms | ActiveRecord: 0.4ms)


Started GET "/policies" for 127.0.0.1 at 2013-03-10 01:03:56 -0500
Processing by PolicyController#index as JSON
Read fragment views/railsdev.com:3000/policies.json (0.4ms)
Completed 200 OK in 1ms (ActiveRecord: 0.0ms)
[2013-03-10 01:03:56] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true

但是,当我将数量增加到 10,000 个 JSON 对象时,它开始查询数据库并在每个请求中重新写入片段。证明人:

Started GET "/policies" for 127.0.0.1 at 2013-03-10 01:12:45 -0500
Processing by PolicyController#index as JSON
Read fragment views/railsdev.com:3000/policies.json (0.3ms)
  VideoPolicy Load (6.8ms)  SELECT `video_policies`.* FROM `video_policies` 
Write fragment views/railsdev.com:3000/policies.json (3.8ms)
Completed 200 OK in 3482ms (Views: 0.2ms | ActiveRecord: 7.5ms)


Started GET "/policies" for 127.0.0.1 at 2013-03-10 01:12:52 -0500
Processing by PolicyController#index as JSON
Read fragment views/railsdev.com:3000/policies.json (0.2ms)
  VideoPolicy Load (1.7ms)  SELECT `video_policies`.* FROM `video_policies` 
Write fragment views/railsdev.com:3000/policies.json (115.0ms)
Completed 200 OK in 3713ms (Views: 0.2ms | ActiveRecord: 1.7ms)
[2013-03-10 01:12:55] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true

我注意到当文件大小超过 1MB 标记时会发生这种情况(巧合的是,这是 memcached 对象的最大大小。我也在使用 memcached。)是否存在某种最大片段大小或其他为什么它不缓存这些?

这也是我的控制器:

class PolicyController < ApplicationController
  caches_action :index, :cache_path => Proc.new {|controller| controller.params }

  def index
    policies = VideoPolicy.all
    respond_to do |format|
      format.html
      format.json{
        render :json => policies.to_json
      }
    end
  end
end

【问题讨论】:

    标签: ruby-on-rails caching


    【解决方案1】:

    我猜是 memcached 的默认页板大小导致了这种情况。

    This讨论讨论这个问题和一些步骤。

    Memcahced man page 表示-I &lt;size&gt; 可用于覆盖默认的 1 mb。您可以尝试将其设置为 2mb 并查看您的应用的行为是否发生变化?

    【讨论】:

      猜你喜欢
      • 2012-10-07
      • 2016-11-18
      • 2013-01-14
      • 1970-01-01
      • 2018-05-01
      • 2015-05-31
      • 1970-01-01
      • 2015-08-05
      • 2019-12-23
      相关资源
      最近更新 更多