cache_fuやmemcachedを使うときに、cacheメソッドがオプションを 受け取ってくれないので不便だなと思っていたのですが、 EdgeRailsでは以下のようなパッチが当たっていて この問題は解決されているようです。

[PATCH] Rails have poor support to work with memcached

Let's assume we have a caching installation with Nginx used as a frontend. Nginx attempts to get page body by key from memcached. If it succeeds (meaning that the page is in memcached), Rails doesn't get control, making this schema extremely fast, up to 3K requests per second. In case memcached doesn't contain cached page by url as a key, Rails receive control, render page and cache it in memcached in order for the next request to be retrieved from memcached.

現状のリリースバージョンのコードでは、以下のようになっています。

vendor/rails/actionpack/lib/action_view/helpers/cache_helper.rb

   1  def cache(name = {}, &block)
   2    @controller.cache_erb_fragment(block, name)
   3  end

これが、EdgeRailsでは以下のように変更されています。

vendor/rails/actionpack/lib/action_view/helpers/cache_helper.rb

   1  def cache(name = {}, options = nil, &block)
   2    template_extension = first_render[/\.(\w+)$/, 1].to_sym
   3   
   4    case template_extension
   5    when :erb, :rhtml
   6      @controller.cache_erb_fragment(block, name, options)
   7    when :rjs
   8      @controller.cache_rjs_fragment(block, name, options)
   9    when :builder, :rxml
  10      @controller.cache_rxml_fragment(block, name, options)
  11    else
  12      # do a last ditch effort for those brave souls using
  13      # different template engines. This should give plugin
  14      # writters a simple hook.
  15      unless @controller.respond_to?("cache_#{template_extension}_fragment")
  16        raise "fragment caching not supported for #{template_extension} files."
  17      end
  18   
  19      @controller.send!("cache_#{template_extension}_fragment", block, name, options)
  20    end
  21  end

posted by Png genki on Fri 11 Jan 2008 at 05:48

Comments:

or Preview
Social Bookmarks
  • Delicious
  • B_entry303
  • Clip_16_12_w
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ