sudo apt-get install memcached
2. Restart memcached
sudo /etc/init.d/memcached restart
3.安裝gem dalli
sudo gem install dalli
4.編輯 config/environments/development.rb
# Memcached config.perform_caching = true config.action_controller.perform_caching = true config.cache_store = :dalli_store, 'localhost:11211'
5. Vim Gemfile file to insert :
gem 'dalli'
測試 railc c
Rails.cache.read('foo') =>nil
Rails.cache.write('foo','test') => true
Rails.cache.read('foo') => 'test'
可以用 fetch 的方式
Rails.cache.fetch('part') do
'xxxxx'
end
查看mencache stats
echo stats | nc 127.0.0.1 11211
即時監看
watch "echo stats | nc 127.0.0.1 11211"
沒有留言:
張貼留言