安装memcached sudo apt-get install memcached
安装后,系统默认会开启一个memcached 服务, 用sudo kill 关闭默认开启的memcached服务进程
开启 memcached服务 memcached start -m 1024 -l 127.0.0.1 -p 11211
安装Dalli sudo gem install Dalli
config/environments/produation.rb下配置
config.cache_store = :dalli_store, 'localhost:11322', { :namespace => "rails-xxx",
:expires_in => 1.day,
:compress => true }
配置OK
查看memcached 状态 telnet 127.0.0.1 11211后,在输入stats
添加Action缓存,controller中使用,caches_action: action_name
清除Action缓存,controller中使用,expire_action :controller => :topn, :action => [:periphery], :format => :json