3
3
cache_environ <- new.env(parent = emptyenv())
4
4
cache_environ $ use_cache <- NULL
5
5
cache_environ $ epidatr_cache <- NULL
6
- # ' create or renew a cache for this session
6
+
7
+ # ' Create or renew a cache for this session
7
8
# ' @aliases set_cache
8
9
# ' @description
9
10
# ' By default, epidatr re-requests data from the API on every call of `fetch`.
@@ -72,8 +73,7 @@ cache_environ$epidatr_cache <- NULL
72
73
# ' dir = "some/subdir",
73
74
# ' days = 14,
74
75
# ' max_size = 512,
75
- # ' logfile = "some/subdir/logs.txt",
76
- # ' prune_rate = 20L
76
+ # ' logfile = "some/subdir/logs.txt"
77
77
# ' )
78
78
# ' }
79
79
# '
@@ -90,15 +90,10 @@ cache_environ$epidatr_cache <- NULL
90
90
# ' @param logfile where cachem's log of transactions is stored, relative to the
91
91
# ' cache directory. By default, it is `"logfile.txt"`. The environmental
92
92
# ' 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.
98
93
# ' @param confirm whether to confirm directory creation. default is `TRUE`;
99
94
# ' 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` ]
102
97
# ' @export
103
98
# ' @import cachem
104
99
# ' @import glue
@@ -107,7 +102,6 @@ set_cache <- function(cache_dir = NULL,
107
102
days = NULL ,
108
103
max_size = NULL ,
109
104
logfile = NULL ,
110
- prune_rate = 2000L ,
111
105
confirm = TRUE ) {
112
106
if (is.null(cache_dir ) && sessionInfo()$ R.version $ major > = 4 ) {
113
107
cache_dir <- Sys.getenv(" EPIDATR_CACHE_DIR" , unset = tools :: R_user_dir(" epidatr" ))
@@ -129,7 +123,7 @@ set_cache <- function(cache_dir = NULL,
129
123
logfile <- Sys.getenv(" EPIDATR_CACHE_LOGFILE" , unset = " logfile.txt" )
130
124
}
131
125
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 ))
133
127
#
134
128
# make sure that that directory exists and drag the user into that process
135
129
cache_exists <- file.exists(cache_dir )
@@ -171,15 +165,14 @@ set_cache <- function(cache_dir = NULL,
171
165
dir = cache_dir ,
172
166
max_size = as.integer(max_size * 1024 ^ 2 ),
173
167
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 )
176
169
)
177
170
}
178
171
}
179
172
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
181
174
# ' @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
183
176
# ' are using a session unique cache, you will have to pass the arguments you
184
177
# ' used for `set_cache` earlier, otherwise the system-wide `.Renviron`-based
185
178
# ' defaults will be used.
@@ -190,15 +183,13 @@ set_cache <- function(cache_dir = NULL,
190
183
# ' days = 14,
191
184
# ' max_size = 512,
192
185
# ' logfile = "some/subdir/logs.txt",
193
- # ' prune_rate = 20L
194
186
# ' )
195
187
# ' }
196
188
# ' @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`]
202
193
# ' @export
203
194
# ' @import cachem
204
195
clear_cache <- function (disable = FALSE , ... ) {
@@ -210,26 +201,26 @@ clear_cache <- function(disable = FALSE, ...) {
210
201
}
211
202
}
212
203
213
- # ' turn off the caching for this session
204
+ # ' Turn off the caching for this session
214
205
# ' @description
215
206
# ' Disable caching until you call `set_cache` or restart R. The files defining
216
207
# ' the cache are untouched. If you are looking to disable the caching more
217
208
# ' permanently, set `EPIDATR_USE_CACHE=FALSE` as environmental variable in
218
209
# ' your `.Renviron`.
219
210
# ' @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` ]
222
213
# ' @import cachem
223
214
disable_cache <- function () {
224
215
cache_environ $ epidatr_cache <- NULL
225
216
}
226
217
227
- # ' describe current cache
218
+ # ' Describe current cache
228
219
# ' @description
229
220
# ' Print out the information about the cache (as would be returned by cachem's
230
221
# ' `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
233
224
# ' disable without deleting
234
225
# ' @export
235
226
cache_info <- function () {
@@ -240,16 +231,16 @@ cache_info <- function() {
240
231
}
241
232
}
242
233
243
- # ' dispatch caching
234
+ # ' Dispatch caching
244
235
# '
245
236
# ' @description
246
237
# ' the guts of caching, its interposed between fetch and the specific fetch
247
238
# ' methods. Internal method only.
248
239
# '
249
240
# ' @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()` ]
251
242
# ' @keywords internal
252
- # ' @import cachem openssl
243
+ # ' @importFrom openssl md5
253
244
cache_epidata_call <- function (epidata_call , fetch_args = fetch_args_list()) {
254
245
is_cachable <- check_is_cachable(epidata_call , fetch_args )
255
246
if (is_cachable ) {
0 commit comments