web middens class
cache
an HoardClient
class, see hoardr::hoard()
for help
cache_path
(character) the cache path
verbose
(logical) verbose or not
new()
Create a new midden
object
midden$new(verbose = FALSE)
verbose
(logical) get messages about whats going on.
default: FALSE
A new midden
object
print()
print method for midden
objects
midden$print(x, ...)
x
self
...
ignored
r()
execute an http request code block
midden$r(...)
...
any function that makes an http request
http response
init()
initialize the class with a path for where to cache data
midden$init( path = NULL, type = "user_cache_dir", prefix = "R", full_path = NULL )
path
(character) the path to be appended to the cache path set
by type
type
(character) the type of cache, see rappdirs
prefix
(character) prefix to the path
value. Default: "R"
full_path
(character) instead of using path
, type
, and prefix
just set the full path with this parameter
NULL
destroy()
remove all cached files in the midden, including directory
midden$destroy()
NULL
cleanup()
remove all cached files in the midden, but leave the directory
midden$cleanup()
NULL
expire()
set an expiration time
midden$expire(expire = NULL, reset = FALSE)
expire
(integer) seconds to expire - OR, set via the
environment variable WEBMIDDENS_EXPIRY_SEC
reset
(logical) reset to NULL
? default: FALSE
NULL
z <- midden$new() z$expire(35) # set to expire all requests in 35 seconds # or set by env var Sys.setenv(WEBMIDDENS_EXPIRY_SEC = 35)
cache_response()
cache response
midden$cache_response(x, exp)
x
a crul HttpResponse
exp
(integer) seconds to expire
clone()
The objects of this class are cloneable with this method.
midden$clone(deep = FALSE)
deep
Whether to make a deep clone.
if (FALSE) { library(crul) # without middens con <- crul::HttpClient$new("https://httpbin.org") con2 <- crul::HttpClient$new("https://google.com") con$get("get", query = list(stuff = "bananas")) con2$get(query = list(q = "stuff")) # with middens x <- midden$new() x x$init(path = "rainforest3") x x$cache x$expire() x$expire(5) x$expire() x$expire(reset = TRUE) x$expire() Sys.setenv(WEBMIDDENS_EXPIRY_SEC = 35) x$expire() x$expire(reset = TRUE) x$expire() # first request is a real HTTP request x$r(con$get("get", query = list(stuff = "bananas"))) # following requests use the cached response x$r(con$get("get", query = list(stuff = "bananas"))) # verbose output x <- midden$new(verbose = TRUE) x$init(path = "rainforest") x$r(con$get("get", query = list(stuff = "bananas"))) # set expiration time x <- midden$new() x$init(path = "grass") x$expire(3) x # real request x$r(con$get("get", query = list(grass = "tall"))) ## before expiry, get mocked response x$r(con$get("get", query = list(grass = "tall"))) Sys.sleep(5) ## after expiry, get real response x$r(con$get("get", query = list(grass = "tall"))) } ## ------------------------------------------------ ## Method `midden$expire` ## ------------------------------------------------ z <- midden$new() z$expire(35) # set to expire all requests in 35 seconds#> [1] 35