diff --git a/R/api_get.R b/R/api_get.R index d18e645a..5ea9de70 100644 --- a/R/api_get.R +++ b/R/api_get.R @@ -35,6 +35,8 @@ api_get <- function(obj) { if (!is.null(cached_obj)) { + cached_obj[["from_cache"]] <- TRUE + return(cached_obj) } @@ -55,7 +57,11 @@ api_get <- function(obj) { if (cache_is_valid(obj[["timeout"]], created)) { - return(readRDS(cache_file_path)) + cached_obj <- readRDS(cache_file_path) + + cached_obj[["from_cache"]] <- TRUE + + return(cached_obj) } else { @@ -110,7 +116,11 @@ api_get <- function(obj) { "[", as.character(Sys.time()), "] ", "Reading from cache: ", hash ) - return(unserialize(cached_obj[[1L]])) + cached_obj <- unserialize(cached_obj[[1L]]) + + cached_obj[["from_cache"]] <- TRUE + + return(cached_obj) } else { @@ -244,6 +254,8 @@ api_get <- function(obj) { obj[["hash"]] <- hash + obj[["from_cache"]] <- FALSE + debug_msg( "[", as.character(Sys.time()), "] ", "Request made to: ", notoken, " ", hash ) @@ -354,12 +366,18 @@ get_timeout <- function(obj) { timeout <- obj[["cache"]] - if (is.logical(timeout)) { + if (is.logical(timeout) || isTRUE(obj[["cache_override"]])) { timeout <- Inf } + if (isFALSE(obj[["cache_override"]])) { + + timeout <- 0 + + } + timeout } diff --git a/R/finbif_records.R b/R/finbif_records.R index 527809d7..d361d171 100644 --- a/R/finbif_records.R +++ b/R/finbif_records.R @@ -781,7 +781,8 @@ request <- function(fb_records_obj) { date_time = fb_records_obj[["date_time_selected"]], aggregate = aggregate, cache = cache, - restricted_api = fb_records_obj[["restricted_api"]] + restricted_api = fb_records_obj[["restricted_api"]], + from_cache = resp[["from_cache"]] ) if (n > max_size) { @@ -836,7 +837,8 @@ get_extra_pages <- function(fb_records_list) { cache = attr(fb_records_list, "cache", TRUE), select_query = attr(fb_records_list, "select", TRUE), aggregate = attr(fb_records_list, "aggregate", TRUE), - restricted_api = attr(fb_records_list, "restricted_api", TRUE) + restricted_api = attr(fb_records_list, "restricted_api", TRUE), + cache_override = attr(fb_records_list, "from_cache", TRUE) ) n <- attr(fb_records_list, "nrec_dnld", TRUE)