How can I cache Model objects in Rails?

2019-04-10 02:10发布

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条回答
女痞
2楼-- · 2019-04-10 03:02
登录 后发表回答