From 861ec91e8c681302cec76d9bce278da829e85df1 Mon Sep 17 00:00:00 2001 From: Angelo capilleri Date: Fri, 31 May 2013 17:59:06 +0200 Subject: [PATCH] add cache_if and cache_unless on caching doc --- guides/source/caching_with_rails.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/guides/source/caching_with_rails.md b/guides/source/caching_with_rails.md index c0cbce81c5bd6..1e196b0e42ec6 100644 --- a/guides/source/caching_with_rails.md +++ b/guides/source/caching_with_rails.md @@ -104,6 +104,15 @@ This method generates a cache key that depends on all products and can be used i All available products: <% end %> ``` + +If you want to cache a fragment under certain condition you can use `cache_if` or `cache_unless` + +```erb +<% cache_if (condition, cache_key_for_products) do %> + All available products: +<% end %> +``` + You can also use an Active Record model as the cache key: ```erb