Description Public fields Methods Examples
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | ## Not run:
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")))
## End(Not run)
## ------------------------------------------------
## Method `midden$expire`
## ------------------------------------------------
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.