From 4bf9e49ec407d47511fc0ede9f6b810483fdcedb Mon Sep 17 00:00:00 2001 From: BelenRemedi Date: Fri, 22 Nov 2019 10:12:00 -0300 Subject: [PATCH] show consitency in cache key and avoid getting into implementation details --- .../lib/action_view/helpers/cache_helper.rb | 2 +- guides/source/caching_with_rails.md | 16 +++++++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/actionview/lib/action_view/helpers/cache_helper.rb b/actionview/lib/action_view/helpers/cache_helper.rb index b0b752834e..a6ace868d6 100644 --- a/actionview/lib/action_view/helpers/cache_helper.rb +++ b/actionview/lib/action_view/helpers/cache_helper.rb @@ -24,7 +24,7 @@ module ActionView # This approach will assume that when a new topic is added, you'll touch # the project. The cache key generated from this call will be something like: # - # views/template/action.html.erb:7a1156131a6928cb0026877f8b749ac9/projects/123 + # views/template/action:7a1156131a6928cb0026877f8b749ac9/projects/123 # ^template path ^template tree digest ^class ^id # # This cache key is stable, but it's combined with a cache version derived from the project diff --git a/guides/source/caching_with_rails.md b/guides/source/caching_with_rails.md index b37562cb59..7f3451d8b5 100644 --- a/guides/source/caching_with_rails.md +++ b/guides/source/caching_with_rails.md @@ -88,20 +88,18 @@ When your application receives its first request to this page, Rails will write a new cache entry with a unique key. A key looks something like this: ``` -views/products/index.html.erb:bea67108094918eeba42cd4a6e786901/products/1 +views/products/index:bea67108094918eeba42cd4a6e786901/products/1 ``` -`products/1` is a stable key but a cache version, derived from the product -record, is stored in the cache entry. When the product `updated_at` is touched, -the `cache_version` changes. Rails will check it when pulling the entry from the -cache and write the new information to the same cache key. This is called recyclable -key-based expiration. - The string of characters in the middle is a template tree digest. It is a hash -digest computed based on the contents of the entire template file. If -you change the template file (e.g., the HTML changes), the digest will change, +digest computed based on the contents of the view fragment you are caching. If +you change the view fragment (e.g., the HTML changes), the digest will change, expiring the existing file. +A cache version, derived from the product record, is stored in the cache entry. +When the product is touched, the cache version changes, and any cached fragments +that contain the previous version are ignored. + TIP: Cache stores like Memcached will automatically delete old cache files. If you want to cache a fragment under certain conditions, you can use