如何在Rails中缓存模型对象? [英] How can I cache Model objects in Rails?

查看:77
本文介绍了如何在Rails中缓存模型对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种我可以在Rails中使用的技术,以便每当对Model对象执行简单的查找"时,都会首先搜索memcached的结果,只有在没有找到结果的情况下,才会对数据库?

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?

理想情况下,我希望解决方案是隐式的,这样我就可以编写Model.find(id),它首先检查缓存,如果需要数据库查询,则需要将返回的对象添加到缓存中即我不需要用其他代码包装Model.find(id)来检查缓存中是否有匹配的内容.

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.

谢谢!

推荐答案

http://github.com/ngmoco/cache-money 是必经之路

这篇关于如何在Rails中缓存模型对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆