LoginSignup
5
4

More than 5 years have passed since last update.

Rails5でdalli+memcachedを使ったセッション管理をする際の注意

Last updated at Posted at 2016-11-22

memcachedを利用したsession管理

たとえば上の記事を参考にRails5にdalliを導入してmemcachedでセッション管理をしようと思っても、development環境ではそのままでは動かない。
Rails5からは、development環境でキャッシュを有効化するには、下記のコマンドを一度実行する必要がある。

キャッシュの有効化
$ rails dev:cache

実際には、development.rbを読めばわかるが、tmp/cache-dev.txtの有無でperform_cachingの値が決定される。

development.rb
...
  # Enable/disable caching. By default caching is disabled.
  if Rails.root.join('tmp/caching-dev.txt').exist?
    config.action_controller.perform_caching = true
    config.cache_store = :dalli_store
    config.public_file_server.headers = {
      'Cache-Control' => 'public, max-age=172800'
    }
  else
    config.action_controller.perform_caching = false
    config.cache_store = :null_store
  end
...

Rails4までは何もしなくてもよかったので、ちょっとしたハマりポイントである。

Caching in development environment in Rails 5

5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4