3
3
cache_environ <- new.env(parent = emptyenv())
4
4
cache_environ $ use_cache <- NULL
5
5
cache_environ $ epidatr_cache <- NULL
6
+ cache_environ $ cache_args <- NULL
6
7
7
8
# ' Create or renew a cache for this session
8
9
# ' @aliases set_cache
@@ -169,6 +170,12 @@ set_cache <- function(cache_dir = NULL,
169
170
max_age = days * 24 * 60 * 60 ,
170
171
logfile = file.path(cache_dir , logfile )
171
172
)
173
+ cache_environ $ cache_args <- list2(
174
+ cache_dir = cache_dir ,
175
+ days = days ,
176
+ max_size = max_size ,
177
+ logfile = logfile
178
+ )
172
179
}
173
180
174
181
cli :: cli_inform(c(
@@ -183,9 +190,9 @@ set_cache <- function(cache_dir = NULL,
183
190
# ' Manually reset the cache, deleting all currently saved data and starting afresh
184
191
# ' @description
185
192
# ' 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 .
189
196
# ' @param disable instead of setting a new cache, disable caching entirely;
190
197
# ' defaults to `FALSE`
191
198
# ' @inheritDotParams set_cache
@@ -198,11 +205,22 @@ set_cache <- function(cache_dir = NULL,
198
205
clear_cache <- function (... , disable = FALSE ) {
199
206
if (any(! is.na(cache_environ $ epidatr_cache ))) {
200
207
cache_environ $ epidatr_cache $ destroy()
208
+ recovered_args <- cache_environ $ cache_args
209
+ cache_environ $ cache_args <- NULL
210
+ } else {
211
+ recovered_args <- list ()
201
212
}
213
+ args <- rlang :: dots_list(
214
+ ... ,
215
+ confirm = FALSE ,
216
+ !!! recovered_args ,
217
+ .homonyms = " first" ,
218
+ .ignore_empty = " all"
219
+ )
202
220
if (disable ) {
203
221
cache_environ $ epidatr_cache <- NULL
204
222
} else {
205
- set_cache(... )
223
+ rlang :: inject( set_cache(!!! args ) )
206
224
}
207
225
}
208
226
0 commit comments