9. Sweepersconfig.action_controller.perform_caching = true app/config/environments/production.rb Proxy (Squid, Varnish) Web Server (Apache, Nginx) Rails Stack (Rack, App) DB (PostgreSQL, MySQL) Browser Cache as earlier as youcan
12. Storedinside the File System onlyconfig.action_controller.page_cache_directory = RAILS_ROOT + “/…” config/environment.rb class Articles < ContentController # Add cache on articles index page caches_page :index app/controllers/articles_controller.rb Proxy Web Server Rails Stack DB Browser public/cache/articles.html
34. Time basedflushing if usingmemcachedclass ArticleSweeper < ActionController::Caching::Sweeper # This sweeper observe articles model and delete cache on save observe :article def after_save(article) clear_article_cache(article) end def clear_article_cache(article) expire_pageindex_path, client end End app/sweepers/article_sweeper.rb
37. Hack for subdomainif any# Check index CACHE set $requested_page $request_uri; # Initialize variables set $cache_path "/cache/views/$http_host/static/"; if ($request_uri ~ ^/$){ set $requested_page "index"; } # Check if the page is in the cache. if (-f $document_root/$cache_path/$requested_page.html) { rewrite (.*) $cache_path/$requested_page.html break; }
43. Intelligent keys- cache(“#{article.id}-#{article.update_at.to_i}” -data) do = My heavy stuffs to cache # => /cache/3-1234567-data #Or just writing - cache(article) do = My heavy stuffs to cache # => /cache/articles/3-1234567 #And if related to a specific user - cache([article,user]) do = My heavy stuffs to cache # => /cache/articles/3-1234567/users/23-12345678