Skip to content

Commit

Permalink
Invalidate (or not) cache for all pages
Browse files Browse the repository at this point in the history
  • Loading branch information
wkmor1 committed Nov 30, 2023
1 parent 4b7c258 commit 761231c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
24 changes: 21 additions & 3 deletions R/api_get.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ api_get <- function(obj) {

if (!is.null(cached_obj)) {

cached_obj[["from_cache"]] <- TRUE

return(cached_obj)

}
Expand All @@ -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 {

Expand Down Expand Up @@ -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 {

Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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

}
Expand Down
6 changes: 4 additions & 2 deletions R/finbif_records.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 761231c

Please sign in to comment.