views:

66

answers:

2

Heroku supports memcache natively as an addon. my problem is, being a rails newbie still, I have no clue how to use memcache in order to speed-up my most time-consuming request (I know which they are by looking a the newrelic analysis). should we use a gem like 'cache-money' on-top of memcache? does anyone use act_as_cached anymore?

I know this is a pretty trivial questions. Yet after searching the web for hours, I could not find a decent tutorial. Any help/link appreciated!

A: 

You can cache on memcache the action_cache or you can access to memcache with Rails.cache

shingara
+3  A: 

You can watch Caching in Rails 2.1 and then read the memcached documentation (I suppose you have already read it) in Heroku.

Also, Touch and Cache is quite interesting technique to avoid writing Sweepers in order to delete cached content when you need to refresh the cached data. Using touch will auto expire cached data with almost no need to write new code.

Please note that today, the Heroku memcached integration assumes you are using Rails >= 2.3.3

The main idea is that you add the result(s) of your time consuming method to Rails.cache (which is the interface through which you access your caching mechanism). When you fetch that result(s) the caching mechanism searches to see if it can find it or if it hasn't expired.

If it finds it, it returns it very fast because it takes it from the cache.

If it doesn't find it or it has expired (you set this when you call fetch), it runs the actual slow method to add it or refresh it in cache.

Finally, it is very useful to read the Rails documentation apart from whether you are using memcached or the built in Rails caching: Caching with Rails: An overview. Among other things it talks about:

  • Page caching
  • Action caching
  • Fragment caching
  • Sweepers
  • SQL caching
  • and more ...
Petros