Returns a new connection object with caching enabled. Cached responses are stored as JSON files in the specified directory, keyed by URL, query parameters and (hashed) token, so connections with different credentials never share an entry.
Arguments
- con
A
brapi_connection()object.- dir
Character. Directory to store cached responses. Defaults to R's per-user cache directory for brapiR2,
tools::R_user_dir("brapiR2", "cache").- ttl
Numeric. Time-to-live for cached entries in seconds. Default 3600 (1 hour).
Examples
con <- brapi_connection("https://test-server.brapi.org")
con <- brapi_cache_enable(con, dir = tempfile("brapi_cache_"), ttl = 7200)
#> ✔ Caching enabled at /tmp/Rtmp1vXenZ/brapi_cache_82549d6cae9 (TTL: 7200s)
con
#>
#> ── BrAPI Connection
#> • Server: <https://test-server.brapi.org>
#> • Version: v2
#> • Auth: ✗ no token
#> • Page size: 1000
#> • Timeout: 120s
#> • Cache: enabled (/tmp/Rtmp1vXenZ/brapi_cache_82549d6cae9)
