knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
httc makes it easy to quickly cache HTTP responses according to cache control headers with drop in wrappers for httr verbs. For more control over caching behaviour, caching()
lets you customize your own cached function.
httc is not on CRAN. You can install the development version on GitHub with:
remotes::install_github("mikmart/httc")
Drop in a httc::GET
instead of httr::GET
to honour cache control headers:
# Response header specifies two seconds of caching cached_request <- function() { try(httc::GET("https://httpbin.org/cache/2")) } system.time(cached_request()) # First response from server system.time(cached_request()) # Second uses cached result Sys.sleep(2) system.time(cached_request()) # Re-requested from server
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.