33cache_environ <- new.env(parent = emptyenv())
44cache_environ $ use_cache <- NULL
55cache_environ $ epidatr_cache <- NULL
6+ cache_environ $ cache_args <- NULL
67
78# ' Create or renew a cache for this session
89# ' @aliases set_cache
@@ -169,6 +170,12 @@ set_cache <- function(cache_dir = NULL,
169170 max_age = days * 24 * 60 * 60 ,
170171 logfile = file.path(cache_dir , logfile )
171172 )
173+ cache_environ $ cache_args <- list2(
174+ cache_dir = cache_dir ,
175+ days = days ,
176+ max_size = max_size ,
177+ logfile = logfile
178+ )
172179 }
173180
174181 cli :: cli_inform(c(
@@ -183,9 +190,9 @@ set_cache <- function(cache_dir = NULL,
183190# ' Manually reset the cache, deleting all currently saved data and starting afresh
184191# ' @description
185192# ' Deletes the current cache and resets a new cache. Deletes local data! If you
186- # ' are using a session unique cache, you will have to pass the arguments you
187- # ' used for `set_cache` earlier, otherwise the system-wide `.Renviron`-based
188- # ' defaults will be used .
193+ # ' are using a session unique cache, the previous settings will be reused. If
194+ # ' you pass in new `set_cache` arguments, they will take precedence over the
195+ # ' previous settings .
189196# ' @param disable instead of setting a new cache, disable caching entirely;
190197# ' defaults to `FALSE`
191198# ' @inheritDotParams set_cache
@@ -198,11 +205,22 @@ set_cache <- function(cache_dir = NULL,
198205clear_cache <- function (... , disable = FALSE ) {
199206 if (any(! is.na(cache_environ $ epidatr_cache ))) {
200207 cache_environ $ epidatr_cache $ destroy()
208+ recovered_args <- cache_environ $ cache_args
209+ cache_environ $ cache_args <- NULL
210+ } else {
211+ recovered_args <- list ()
201212 }
213+ args <- rlang :: dots_list(
214+ ... ,
215+ confirm = FALSE ,
216+ !!! recovered_args ,
217+ .homonyms = " first" ,
218+ .ignore_empty = " all"
219+ )
202220 if (disable ) {
203221 cache_environ $ epidatr_cache <- NULL
204222 } else {
205- set_cache(... )
223+ rlang :: inject( set_cache(!!! args ) )
206224 }
207225}
208226
0 commit comments