守破離でいこう! -Let's go with SyuHaRi!-

2007/01/30

ActiveRecodStoreな場合のセッションの掃除

Railsでは、セッションが自動生成されるのですが、自動削除はしてくれません。
ですので、自分で掃除をしなければいけません。

session_cleaner.rb

class SessionCleaner
  def self.remove_stale_sessions
    CGI::Session::ActiveRecordStore::Session.destroy_all(['updated_on < ?', 1.days.ago])
  end
end
上記クラスをlibあたりに保存し、cronで毎日自動実行させます。
0 0 * * * ruby /full/path/to/script/runner -e production "SessionCleaner.remove_stale_sessions"

参考:
Removing Stale Rails Sessions

ラベル:

automatically translated by Google Translate Hack!

naoki 15:15
HaloScan: |

0 Comments:

Add a comment