how to use memcache to speed

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!


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

  • 您可以在memcache上缓存action_cache,也可以使用Rails.cache访问memcache

    链接地址: http://www.djcxy.com/p/48086.html

    上一篇: 如何在一些Python代码中追踪Heisenbug?

    下一篇: 如何使用memcache加快速度