2013-04-03 71 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