33cache_environ <- new.env(parent = emptyenv())
44cache_environ $ use_cache <- NULL
55cache_environ $ epidatr_cache <- NULL
6- # ' create or renew a cache for this session
6+
7+ # ' Create or renew a cache for this session
78# ' @aliases set_cache
89# ' @description
910# ' By default, epidatr re-requests data from the API on every call of `fetch`.
@@ -72,8 +73,7 @@ cache_environ$epidatr_cache <- NULL
7273# ' dir = "some/subdir",
7374# ' days = 14,
7475# ' max_size = 512,
75- # ' logfile = "some/subdir/logs.txt",
76- # ' prune_rate = 20L
76+ # ' logfile = "some/subdir/logs.txt"
7777# ' )
7878# ' }
7979# '
@@ -90,15 +90,10 @@ cache_environ$epidatr_cache <- NULL
9090# ' @param logfile where cachem's log of transactions is stored, relative to the
9191# ' cache directory. By default, it is `"logfile.txt"`. The environmental
9292# ' variable is `EPIDATR_CACHE_LOGFILE`.
93- # ' @param prune_rate how many calls to go between checking if any cache elements
94- # ' are too old or if the cache overall is too large. Defaults to `2000L`.
95- # ' Since cachem fixes the max time between prune checks to 5 seconds, there's
96- # ' little reason to actually change this parameter. Doesn't have a
97- # ' corresponding environmental variable.
9893# ' @param confirm whether to confirm directory creation. default is `TRUE`;
9994# ' should only be set in non-interactive scripts
100- # ' @seealso [clear_cache] to delete the old cache while making a new one,
101- # ' [disable_cache] to disable without deleting, and [cache_info]
95+ # ' @seealso [` clear_cache` ] to delete the old cache while making a new one,
96+ # ' [` disable_cache` ] to disable without deleting, and [` cache_info` ]
10297# ' @export
10398# ' @import cachem
10499# ' @import glue
@@ -107,7 +102,6 @@ set_cache <- function(cache_dir = NULL,
107102 days = NULL ,
108103 max_size = NULL ,
109104 logfile = NULL ,
110- prune_rate = 2000L ,
111105 confirm = TRUE ) {
112106 if (is.null(cache_dir ) && sessionInfo()$ R.version $ major > = 4 ) {
113107 cache_dir <- Sys.getenv(" EPIDATR_CACHE_DIR" , unset = tools :: R_user_dir(" epidatr" ))
@@ -129,7 +123,7 @@ set_cache <- function(cache_dir = NULL,
129123 logfile <- Sys.getenv(" EPIDATR_CACHE_LOGFILE" , unset = " logfile.txt" )
130124 }
131125 stopifnot(is.character(logfile ))
132- stopifnot(is.numeric(days ), is.numeric(max_size ), is.integer( prune_rate ) )
126+ stopifnot(is.numeric(days ), is.numeric(max_size ))
133127 #
134128 # make sure that that directory exists and drag the user into that process
135129 cache_exists <- file.exists(cache_dir )
@@ -171,15 +165,14 @@ set_cache <- function(cache_dir = NULL,
171165 dir = cache_dir ,
172166 max_size = as.integer(max_size * 1024 ^ 2 ),
173167 max_age = days * 24 * 60 * 60 ,
174- logfile = file.path(cache_dir , logfile ),
175- prune_rate = prune_rate
168+ logfile = file.path(cache_dir , logfile )
176169 )
177170 }
178171}
179172
180- # ' manually reset the cache, deleting all currently saved data and starting afresh
173+ # ' Manually reset the cache, deleting all currently saved data and starting afresh
181174# ' @description
182- # ' deletes the current cache and resets a new cache. Deletes local data! If you
175+ # ' Deletes the current cache and resets a new cache. Deletes local data! If you
183176# ' are using a session unique cache, you will have to pass the arguments you
184177# ' used for `set_cache` earlier, otherwise the system-wide `.Renviron`-based
185178# ' defaults will be used.
@@ -190,15 +183,13 @@ set_cache <- function(cache_dir = NULL,
190183# ' days = 14,
191184# ' max_size = 512,
192185# ' logfile = "some/subdir/logs.txt",
193- # ' prune_rate = 20L
194186# ' )
195187# ' }
196188# ' @param disable instead of setting a new cache, disable caching entirely;
197- # ' defaults to `FALSE`
198- # ' @param ... see the `set_cache` arguments below
199- # ' @inheritParams set_cache
200- # ' @seealso [set_cache] to start a new cache (and general caching info),
201- # ' [disable_cache] to only disable without deleting, and [cache_info]
189+ # ' defaults to `FALSE`
190+ # ' @param ... arguments passed to `set_cache`
191+ # ' @seealso [`set_cache`] to start a new cache (and general caching info),
192+ # ' [`disable_cache`] to only disable without deleting, and [`cache_info`]
202193# ' @export
203194# ' @import cachem
204195clear_cache <- function (disable = FALSE , ... ) {
@@ -210,26 +201,26 @@ clear_cache <- function(disable = FALSE, ...) {
210201 }
211202}
212203
213- # ' turn off the caching for this session
204+ # ' Turn off the caching for this session
214205# ' @description
215206# ' Disable caching until you call `set_cache` or restart R. The files defining
216207# ' the cache are untouched. If you are looking to disable the caching more
217208# ' permanently, set `EPIDATR_USE_CACHE=FALSE` as environmental variable in
218209# ' your `.Renviron`.
219210# ' @export
220- # ' @seealso [set_cache] to start a new cache (and general caching info),
221- # ' [clear_cache] to delete the cache and set a new one, and [cache_info]
211+ # ' @seealso [` set_cache` ] to start a new cache (and general caching info),
212+ # ' [` clear_cache` ] to delete the cache and set a new one, and [` cache_info` ]
222213# ' @import cachem
223214disable_cache <- function () {
224215 cache_environ $ epidatr_cache <- NULL
225216}
226217
227- # ' describe current cache
218+ # ' Describe current cache
228219# ' @description
229220# ' Print out the information about the cache (as would be returned by cachem's
230221# ' `info()` method)
231- # ' @seealso [set_cache] to start a new cache (and general caching info),
232- # ' [clear_cache] to delete the cache and set a new one, and [disable_cache] to
222+ # ' @seealso [` set_cache` ] to start a new cache (and general caching info),
223+ # ' [` clear_cache` ] to delete the cache and set a new one, and [` disable_cache` ] to
233224# ' disable without deleting
234225# ' @export
235226cache_info <- function () {
@@ -240,16 +231,16 @@ cache_info <- function() {
240231 }
241232}
242233
243- # ' dispatch caching
234+ # ' Dispatch caching
244235# '
245236# ' @description
246237# ' the guts of caching, its interposed between fetch and the specific fetch
247238# ' methods. Internal method only.
248239# '
249240# ' @param call the `epidata_call` object
250- # ' @param fetch_args the args list for fetch as generated by [fetch_args_list()]
241+ # ' @param fetch_args the args list for fetch as generated by [` fetch_args_list()` ]
251242# ' @keywords internal
252- # ' @import cachem openssl
243+ # ' @importFrom openssl md5
253244cache_epidata_call <- function (epidata_call , fetch_args = fetch_args_list()) {
254245 is_cachable <- check_is_cachable(epidata_call , fetch_args )
255246 if (is_cachable ) {
0 commit comments