views:

503

answers:

1

Hello there,

I am using memcached in production on a high traffic website and have only just switched to using Rails.

I am using Rails 2.3.2.

My question is: Is caching of of queries done automatically with this version of Rails? Or do I have to explicitly cache these queries?

I have seen conflicting documentation on this issue, and I am afraid of having to restart memcached to see exactly what is happening.

The documentation on this w.r.t rails seems patchy. I would appreciate if you could also point out the best place to read up on this.

Thanks! Vikram

+4  A: 

If you haven't explicitly set out and configured certain actions to be cached they won't be, so I would guess right now that you aren't actually using your memcached like you think you are.

As a starting point I'd recommend reading this article on the different methods of setting up caching within Rails.

I've also found this presentation to be useful as well as this excellent screencast.

If you're looking for help, it would be useful to know more of what you're trying to do: how write heavy is the application? How may pages / views / users are you trying to serve?

Mike Buckbee
Thanks Mike. My question is specifically regarding queries. Are you saying that unless I specify it within my controllers what queries I want to cache, it won't happen automatically? I thought that in production, caching was enabled by default. I am worried now :). Memcached is using all of the allocated memory, so what is it caching exactly?
Vikram Goyal
The term "cached" can mean different things in context. In production queries are "cached" meaning that at each request of the page if a query is called twice (or 20 times) only one actual request will be made against the server.
Mike Buckbee
I'd highly recommend reading the first article I linked to in my answer.
Mike Buckbee
Thanks Mike,So does that mean, in production, my queries are automatically being cached in memcached?
Vikram Goyal
@Mike: Queries are cached in ActiveRecord's cache in the development environment too. You can see it in the log - it says "CACHE". I think Vikram is probably thinking of the production default setting whereby classes are cached i.e. not reloaded on each request.
John Topley