Skip to content

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).

Usage

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, 17 Aug 2022 14:41:44 GMT <expired>
#>   Last-Modified: 
#>   Etag:          
r1$date
#> [1] "2022-08-17 14:41:44 GMT"
rerequest(r1)$date
#> [1] "2022-08-17 14:41:45 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, 17 Aug 2023 14:41:45 GMT
#>   Last-Modified: Tue, 22 Oct 2019 18:30:00 GMT
#>   Etag:          
r2$date
#> [1] "2022-08-17 14:41:45 GMT"
rerequest(r2)$date
#> [1] "2022-08-17 14:41:45 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, 17 Aug 2022 14:41:45 GMT
#>   Etag:          0c47459bbe134aae8e7d189898ba0037
r3$date
#> [1] "2022-08-17 14:41:45 GMT"
rerequest(r3)$date
#> [1] "2022-08-17 14:41:45 GMT"

# Expires after 5 seconds
if (FALSE) {
r4 <- GET("http://httpbin.org/cache/5")
cache_info(r4)
r4$date
rerequest(r4)$date
Sys.sleep(5)
cache_info(r4)
rerequest(r4)$date
}