开发者

how to use memcache to speed-up rails/heroku

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 开发者_JS百科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!


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 ...


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜