<body><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener('load', function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <div id="navbar-iframe-container"></div> <script type="text/javascript" src="https://apis.google.com/js/platform.js"></script> <script type="text/javascript"> gapi.load("gapi.iframes:gapi.iframes.style.bubble", function() { if (gapi.iframes && gapi.iframes.getContext) { gapi.iframes.getContext().openChild({ url: 'https://www.blogger.com/navbar.g?targetBlogID\x3d4684235500622716427\x26blogName\x3dCaiwangqin\x27s+blog\x26publishMode\x3dPUBLISH_MODE_HOSTED\x26navbarType\x3dBLUE\x26layoutType\x3dCLASSIC\x26searchRoot\x3dhttp://blog.caiwangqin.com/search\x26blogLocale\x3dzh_CN\x26v\x3d2\x26homepageUrl\x3dhttp://blog.caiwangqin.com/\x26vt\x3d3393395200455623441', where: document.getElementById("navbar-iframe-container"), id: "navbar-iframe" }); } }); </script>

Caiwangqin's blog

Focus on Life, Cloud Service, Smart Hardware, Architecture, Technic and beyond…

详细解读Rails Caching

2006年9月10日星期日

问题出现:


I am trying to use caches_action and the agile book says that it is keyed

off the URL, however it does not seem to pick up the URL parameters.


http://localhost:3000/controller/action/id?foo=bar

and

http://localhost:3000/controller/action/id?foo=foobar


Returns the same page.


问题原因:


Rails Caching不能Cache Parameter,所以caches_action时会出现上述原因。 


解决方法:


1. 修改rails routes.rb,将原来的”?parameters=”的调用方式更改为/action/:parameters的访问方式,以使用rails cache不同的fragment


2. 安装一个rails-caching的plugin,然后修改environment.rb中增加cache key for action : Action Cache Update Plugin


参考资料:


http://wiki.rubyonrails.org/rails/pages/Action+Cache+Update+Plugin


http://blog.craz8.com/articles/2005/12/26/rails-action-cache-upgrade 


http://scottstuff.net/presentations/rails-caching/


http://lists.rubyonrails.org/pipermail/rails/2006-February/017726.html


 


标签:

posted by Caiwangqin, 01:15

0 Comments:

发表评论

订阅 博文评论 [Atom]

<< 主页