ポリシー コントローラーにアクション キャッシュを実装しようとしていますが、レンダリングされたフラグメントのサイズが大きくなったときに、キャッシュされたフラグメントを再利用していません。
アクション「インデックス」が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 オブジェクトに増やすと、DB へのクエリが開始され、リクエストごとにフラグメントが再書き込みされます。証拠:
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
これは、ファイル サイズが 1 MB マークを超えたときに発生することに気付きました (これは偶然にも 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