使用Rails片段缓存工作,为什么SELECT语句出现在我的日志里面的缓存片段?

时间:2013-04-03 22:54:03

标签: ruby-on-rails caching memcached fragment-caching

我刚刚使用memcachier和dalli在Heroku上托管的网站上安装了memcached。我已将我的主页包装在片段缓存块中。在我的日志中,我可以看到片段正在缓存并正确读取,我已经发现负载测试的结果已经大大改善了。但我想知道为什么我仍然会看到所有这些模型查找。我的理解是,我应该能够完全避免数据库之旅。我的日志中的“Country Load”语句是否表示从缓存中加载模型?或者我可以通过改变我的缓存方式来避免它们吗?

感谢您的帮助!

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)

1 个答案:

答案 0 :(得分:0)

视图中的片段缓存不会捕获布局 - 您是否有显示国家/地区的页眉或页脚元素?您也可以将它们包装在另一个片段缓存中。