2013-04-03 48 views
0

我剛剛使用memcachier和dalli在Heroku上託管了我的網站上的memcached安裝程序。我已將我的主頁封裝在分段緩存塊中。在我的日誌中,我可以看到片段正在緩存並正確讀取,而且我已經發現負載測試的結果已經大大改善。但我想知道爲什麼我仍然看到所有這些模型查找發生。我的理解是我應該能夠完全避免去數據庫之旅。我的日誌中的「Country Load」語句是否代表從緩存中加載模型?或者我可以通過改變我如何緩存來避免它們?使用Rails片段緩存工作,爲什麼SELECT語句出現在緩存片段內的日誌中?

感謝您的幫助!在視圖

2013-04-03T22:48:03+00:00 app[web.1]: Read fragment views/home (15.4ms) 
2013-04-03T22:48:03+00:00 app[web.1]: Rendered shared/_home.html (18.8ms) 
2013-04-03T22:48:03+00:00 app[web.1]: Rendered cities/index.html within layouts/application (51.6ms) 
2013-04-03T22:48:03+00:00 app[web.1]: Country Load (9.7ms) SELECT "countries".* FROM "countries" WHERE "countries"."name" = 'united states' LIMIT 1 
2013-04-03T22:48:03+00:00 app[web.1]: Country Load (5.0ms) SELECT "countries".* FROM "countries" WHERE "countries"."name" = 'france' LIMIT 1 
2013-04-03T22:48:03+00:00 app[web.1]: Country Load (4.1ms) SELECT "countries".* FROM "countries" WHERE "countries"."name" = 'spain' LIMIT 1 
2013-04-03T22:48:03+00:00 app[web.1]: Country Load (4.3ms) SELECT "countries".* FROM "countries" WHERE "countries"."name" = 'united kingdom' LIMIT 1 
2013-04-03T22:48:03+00:00 app[web.1]: Country Load (3.4ms) SELECT "countries".* FROM "countries" WHERE "countries"."name" = 'brazil' LIMIT 1 
2013-04-03T22:48:03+00:00 app[web.1]: Country Load (3.5ms) SELECT "countries".* FROM "countries" WHERE "countries"."name" = 'china' LIMIT 1 
2013-04-03T22:48:03+00:00 app[web.1]: Country Load (3.0ms) SELECT "countries".* FROM "countries" WHERE "countries"."name" = 'germany' LIMIT 1 
2013-04-03T22:48:03+00:00 app[web.1]: Country Load (2.8ms) SELECT "countries".* FROM "countries" WHERE "countries"."name" = 'argentina' LIMIT 1 
2013-04-03T22:48:03+00:00 app[web.1]: Country Load (12.9ms) SELECT "countries".* FROM "countries" WHERE "countries"."name" = 'japan' LIMIT 1 
2013-04-03T22:48:03+00:00 app[web.1]: Country Load (2.9ms) SELECT "countries".* FROM "countries" WHERE "countries"."name" = 'italy' LIMIT 1 
2013-04-03T22:48:03+00:00 app[web.1]: Country Load (3.6ms) SELECT "countries".* FROM "countries" WHERE "countries"."name" = 'canada' LIMIT 1 
2013-04-03T22:48:03+00:00 app[web.1]: Country Load (3.3ms) SELECT "countries".* FROM "countries" WHERE "countries"."name" = 'thailand' LIMIT 1 
2013-04-03T22:48:03+00:00 app[web.1]: Country Load (3.2ms) SELECT "countries".* FROM "countries" WHERE "countries"."name" = 'colombia' LIMIT 1 
2013-04-03T22:48:03+00:00 app[web.1]: Country Load (3.6ms) SELECT "countries".* FROM "countries" WHERE "countries"."name" = 'south korea' LIMIT 1 
2013-04-03T22:48:03+00:00 app[web.1]: Country Load (10.7ms) SELECT "countries".* FROM "countries" WHERE "countries"."name" = 'sweden' LIMIT 1 
2013-04-03T22:48:03+00:00 app[web.1]: Country Load (3.0ms) SELECT "countries".* FROM "countries" WHERE "countries"."name" = 'singapore' LIMIT 1 
2013-04-03T22:48:03+00:00 app[web.1]: Completed 200 OK in 743ms (Views: 359.6ms | ActiveRecord: 382.2ms) 
+0

你會提供一些來自你的控制器和視圖的代碼嗎? – 2013-04-03 22:58:52

回答

0

片段緩存不會趕上佈局 - 你有一個顯示國家頁眉或頁腳元素?您也可以將這些包裝在另一個片段緩存中。

+0

看起來你是對的。我忘記了我在佈局中做了一些愚蠢的數據庫調用。但我現在也緩存了這些電話。謝謝你的提示! – newtorails 2013-04-03 23:52:44

+0

是的,發生了。小心過濾器也一樣。 – Swards 2013-04-05 04:41:53