| cache_remember | R Documentation |
Attempts to retrieve a cached value by name. If the cache doesn't exist, is expired, or a refresh is requested, evaluates the expression and caches the result. This is the primary caching interface for expensive computations.
cache_remember(
name,
expr,
file = NULL,
expire_after = NULL,
refresh = FALSE,
expire = NULL
)
name |
The cache name (non-empty string identifier) |
expr |
The expression to evaluate and cache if cache miss occurs. Expression is evaluated in the parent frame. |
file |
Optional file path to store the cache
(default: |
expire_after |
Optional expiration time in hours (default: from config). Character durations like "1 day" or "2 hours" are accepted. |
refresh |
Optional boolean or function that returns boolean to force refresh. If TRUE or if function returns TRUE, cache is invalidated and expression is re-evaluated. |
expire |
Optional alias for |
The cached value (if cache hit) or the result of evaluating expr (if cache miss or refresh requested)
if (FALSE) {
# Cache expensive computation
result <- cache_remember("my_analysis", {
expensive_computation()
})
# Force refresh when data changes
result <- cache_remember("analysis", {
run_analysis()
}, refresh = file.mtime("data.csv") > cache_time)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.