How can I cache Model objects in Rails?

巧了我就是萌 提交于 2019-12-06 05:51:41

问题


Is there a technique that I can use in Rails so that whenever a simple "find" is performed on a Model object, memcached is first searched for the result, only if no result is found will a query by then made to the database?

Ideally, I'd like the solution to be implicit, so that I can just write Model.find(id), it first checks the cache and if a database query is required that the object returned is then added to the cache i.e. I don't need to wrap the Model.find(id) with additional code to check the cache for matching contents.

Thanks!


回答1:


http://github.com/ngmoco/cache-money is the way to go



来源:https://stackoverflow.com/questions/3860472/how-can-i-cache-model-objects-in-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!