= Caching in a Multilanguage Environment by Benjamin Krause == Benjamin Krause Of omdb.org == Caching in Rails * Page Caching * Action Caching * Fragment Caching Great, but DHH expects a website to be in English only === Page Caching The webserver handles everything about that page No routing, filters, controller or rendering Webserver gets the request - if the file exists in the location, it will just serve it, otherwise it will route it through to Rails === Fragment caching Parts of a page is cached and used in the render phase == Problems with caching in Rails * No support for caching in different languages * No support to expire all language-caches at once * No support for language-negotation == Conent Negotation - let the user decide, what he wants to see - consists of format negotiation and ... === Format negoatiation HTTP "Accept" Header Accept: Rails supports format negotiation Rails allows you to request a format explicitly === Language negoation HTTP "Accept-Language" Header Rails ignors the HTTP Header == Lets fix that - extending Rails - everything here is available as a plugin and as a patch === Language Routes map.resources :movies Format /2062.html.de # .de added! Implemented by extending with another route with .:format.:lang Added default_language and accepts_languages == Multilanguage View caching === Page caching just add caches_page directive - it will store just the html page Need to add language to cache_page's url_for call == Apache - how to use Apache's content negotiations We need to add the %{LA-U} Rewrite condition - Can be used for look-aheads which perform intial negoation Override with cookie SetEnvIf Cookie "language=(..)" prefer-language=$1 === Fragment caching <% cache do %> .. <% end %> Places the content into MemCache Has created their own MemCache implementation, which uses one MemCache for each language expire_fragment now also supports the :lang parameter == Testing - how to test the views You can set the accept header in a functional test - language has been added assert_cached_page do ... end assert_no_cached_page do ... end assert_cached_fragment( params ) ... end == Plugins svn.omdb-beta.org/plugins/mlr # Multilanguage Routing svn.omdb-beta.org/plugins/mlcache # Multilanguage Caching blog.omdb-beta.org