@@ -138,7 +138,9 @@ cache_prune_if_needed <- function(req, threshold = 60, debug = FALSE) {
138138
139139 last_prune <- the $ cache_throttle [[path ]]
140140 if (is.null(last_prune ) || last_prune + threshold < = Sys.time()) {
141- if (debug ) cli :: cli_text(" Pruning cache" )
141+ if (debug ) {
142+ cli :: cli_text(" Pruning cache" )
143+ }
142144 cache_prune(path , max = req $ policies $ cache_max , debug = debug )
143145 the $ cache_throttle [[path ]] <- Sys.time()
144146
@@ -186,8 +188,9 @@ cache_info <- function(path, pattern = "\\.rds$") {
186188
187189cache_prune_files <- function (info , to_remove , why , debug = TRUE ) {
188190 if (any(to_remove )) {
189- if (debug )
191+ if (debug ) {
190192 cli :: cli_text(" Deleted {sum(to_remove)} file{?s} that {?is/are} {why}" )
193+ }
191194
192195 file.remove(info $ name [to_remove ])
193196 info [! to_remove , ]
@@ -217,18 +220,24 @@ cache_pre_fetch <- function(req, path = NULL) {
217220 if (is.null(cached_resp )) {
218221 return (req )
219222 }
220- if (debug ) cli :: cli_text(" Found url in cache {.val {hash(req$url)}}" )
223+ if (debug ) {
224+ cli :: cli_text(" Found url in cache {.val {hash(req$url)}}" )
225+ }
221226
222227 info <- resp_cache_info(cached_resp )
223228 if (! is.na(info $ expires ) && info $ expires > = Sys.time()) {
224229 signal(" " , " httr2_cache_cached" )
225- if (debug ) cli :: cli_text(" Cached value is fresh; using response from cache" )
230+ if (debug ) {
231+ cli :: cli_text(" Cached value is fresh; using response from cache" )
232+ }
226233
227234 resp <- cached_resp
228235 resp $ body <- cache_body(cached_resp , path )
229236 resp
230237 } else {
231- if (debug ) cli :: cli_text(" Cached value is stale; checking for updates" )
238+ if (debug ) {
239+ cli :: cli_text(" Cached value is stale; checking for updates" )
240+ }
232241 req_headers(
233242 req ,
234243 `If-Modified-Since` = info $ last_modified ,
@@ -248,16 +257,18 @@ cache_post_fetch <- function(req, resp, path = NULL) {
248257
249258 if (is_error(resp )) {
250259 if (cache_use_on_error(req ) && ! is.null(cached_resp )) {
251- if (debug )
260+ if (debug ) {
252261 cli :: cli_text(" Request errored; retrieving response from cache" )
262+ }
253263 cached_resp
254264 } else {
255265 resp
256266 }
257267 } else if (resp_status(resp ) == 304 && ! is.null(cached_resp )) {
258268 signal(" " , " httr2_cache_not_modified" )
259- if (debug )
269+ if (debug ) {
260270 cli :: cli_text(" Cached value still ok; retrieving body from cache" )
271+ }
261272
262273 # Combine headers
263274 resp $ headers <- cache_headers(cached_resp , resp )
@@ -268,7 +279,9 @@ cache_post_fetch <- function(req, resp, path = NULL) {
268279 cache_set(req , resp )
269280 resp
270281 } else if (resp_is_cacheable(resp )) {
271- if (debug ) cli :: cli_text(" Saving response to cache {.val {hash(req$url)}}" )
282+ if (debug ) {
283+ cli :: cli_text(" Saving response to cache {.val {hash(req$url)}}" )
284+ }
272285
273286 cache_set(req , resp )
274287 resp
0 commit comments