MerbのCacheはなかなか優れた設計なので面白いのですが、 開発中にログにCache Miss/Hitの具合が分かるように出力してほしかったので、 development環境用のLoggingMemcachedStoreというのを書いてみました。

   1  class LoggingMemcachedStore < Merb::Cache::MemcachedStore
   2    include Extlib::Hook
   3   
   4    before :read do |key, params|
   5      if exists?(key, params)
   6        Merb.logger.debug "Cache Hit: #{key}"
   7      else
   8        Merb.logger.debug "Cache Miss: #{key}"
   9      end
  10    end
  11   
  12    before :write do |key, data, params, conds|
  13      Merb.logger.debug "Cache Write: #{key}"
  14    end
  15  end

こんな感じでログに出ます。

   1  merb : worker (port 4000) ~ Cache Hit: Plugins#show
   2  merb : worker (port 4000) ~ Cache Write: Plugins#show

posted by Png genki on Sat 21 Feb 2009 at 01:27
Contents
MerbのCacheのHit/Missをログに出力する
Comments
瀧内元気: MacOS版は以下にあります * [genki/ViMouse](https://githu... '23-1
dsjf: https://gist.github.com/6bf1bf2c3cbb5eb6e7a7 これ... '13-1
瀧内元気: おお、チェックしてみます。thx! '11-12
overisland: Reeder for iPhone もこの UI を実装していますね。 '11-12
瀧内元気: その情報は見たのですが、以下のサイトによると、現在はまた必要になってるっぽいんですよね。 ... '11-12
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ