mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
show consitency in cache key and avoid getting into implementation details
This commit is contained in:
parent
ada6055e1f
commit
4bf9e49ec4
2 changed files with 8 additions and 10 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue