Rails 缓存实践

cache

redis

http://redis.io/

redis-objects

redis
redis-objects不好处有3,用文章hits举例:1)redis_key和原来model里的字段重名的话会覆盖;2)取值要article.hits.value不直观3)没有提供可选的持久话方案

1
2
3
4
5
6
7
$ brew install redis
To have launchd start redis at login:
$ ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents
Then to load redis now:
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
Or, if you don't want/need launchctl, you can just run:
$ redis-server /usr/local/etc/redis.conf

Keywords:

  • counter
    • increment
    • decrement
  • hash_key
  • list
    Lists work just like Ruby arrays:
  • set
    Sets work like the Ruby Set class. They are unordered, but guarantee uniqueness of members.
  • sort_set
  • value
  • redis_id_field

  • redis.get

  • redis.smembers

Redis Rails

https://github.com/redis-store/redis-rails

redis-store

https://github.com/redis-store/redis-store

Memcached

###dalli
https://github.com/mperham/dalli

REF::

Redis命令参考简体中文版

Caching with Rails: An overview
Using Redis with Ruby on Rails
RailsCast #115 Model Caching
https://github.com/Shopify/identity_cache
Heroku - Caching Strategies for Rails
Advanced Caching in Rails: Revised
Scaling Rails – 第八章 Memcached
http://www.sitepoint.com/introduction-to-using-redis-with-rails/