You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR introduces a new helper method to support fragment caching. I’ve
been reluctant to add fragment caching because it’s difficult to expire
the cache when templates change and I didn’t want to try to build up a
static dependency tree between components, partials, etc.
For now, we’re keeping it simple by expiring the cache on each deploy
via a deploy key (see below).
**Example:**
```ruby
cache @products do
@products.each do |product|
cache product do
h1 { product.name }
end
end
end
```
The `cache` method will take user cache keys and combine them with
built-in supplemental keys to cache the captured content against.
`cache` will call `cache_store`, which must return a Phlex cache store.
## Supplemental keys
The `cache` method supplements your cache keys with the following:
1. `Phlex::DEPLOY_KEY` — the time that the app was booted and Phlex was
loaded.
5. The name of the class where the caching is taking place. This
prevents collisions between classes.
6. The name of the method where the caching is taking place. This
prevents collisions between different methods in the same class.
7. The line number where the `cache` method is called. This prevents
collisions between different lines, especially when no custom cache keys
are provided.
## Low level caching
The `low_level_cache` method requires a cache key from you and you
control the entire cache key.
## Cache store interface
Cache stores are objects that respond to `fetch(key, &content)`. This
method must return the result of `yield` or a previously cached result
of `yield`. This method may raise if the result of `yield` is not a
string or if the key is not valid.
It’s up to you what keys are valid, but note that Phlex itself uses
arrays, string and integers in its keys.
This interface is a subset of Rails’ cache interface, meaning Rails
cache interface implements this interface can can be used as a Phlex
cache store.
## `FIFOCacheStore`
This PR also introduces a new cache store based on the `Phlex::FIFO`.
This is an extremely fast in-memory cache store that evicts keys on a
first-in-first-out basis. It can be initialised with a max bytesize.
0 commit comments