cache_info() gives details of cacheability of a response, rerequest() re-performs the original request doing as little work as possible (if not expired, returns response as is, or performs revalidation if Etag or Last-Modified headers are present).

cache_info(r)

rerequest(r)

Arguments

r

A response

Examples

# Never cached, always causes redownload r1 <- GET("https://www.google.com") cache_info(r1)
#> <cache_info> https://www.google.com/ #> Cacheable: TRUE #> Expires: Wed, 16 Aug 2017 14:11:51 GMT <expired> #> Last-Modified: #> Etag:
r1$date
#> [1] "2017-08-16 14:11:51 GMT"
rerequest(r1)$date
#> [1] "2017-08-16 14:11:52 GMT"
# Expires in a year r2 <- GET("https://www.google.com/images/srpr/logo11w.png") cache_info(r2)
#> <cache_info> https://www.google.com/images/srpr/logo11w.png #> Cacheable: TRUE #> Expires: Thu, 16 Aug 2018 14:11:52 GMT #> Last-Modified: Fri, 16 Dec 2016 12:30:00 GMT #> Etag:
r2$date
#> [1] "2017-08-16 14:11:52 GMT"
rerequest(r2)$date
#> [1] "2017-08-16 14:11:52 GMT"
# Has last-modified and etag, so does revalidation r3 <- GET("http://httpbin.org/cache") cache_info(r3)
#> <cache_info> http://httpbin.org/cache #> Cacheable: TRUE #> Last-Modified: Wed, 16 Aug 2017 14:11:52 GMT #> Etag: b89a906a2de54d479db9fc9ccae9797d
r3$date
#> [1] "2017-08-16 14:11:51 GMT"
rerequest(r3)$date
#> [1] "2017-08-16 14:11:51 GMT"
# Expires after 5 seconds
# NOT RUN { r4 <- GET("http://httpbin.org/cache/5") cache_info(r4) r4$date rerequest(r4)$date Sys.sleep(5) cache_info(r4) rerequest(r4)$date # }