Skip to content

Commit

Permalink
allow user to force the cache even if probably_cran() is TRUE
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcaseb committed Aug 17, 2023
1 parent 22b7132 commit 9a0222a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions R/cache.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ nfl4th_fdmodel_path <- function() file.path(R_user_dir("nfl4th", "cache"), "fd_m
nfl4th_wpmodel_path <- function() file.path(R_user_dir("nfl4th", "cache"), "wp_model.rds")

.games_nfl4th <- function(){
if (probably_cran()) return(get_games_file())
if (probably_cran() && !force_cache()) return(get_games_file())
if (!file.exists(nfl4th_games_path())){
saveRDS(get_games_file(), nfl4th_games_path())
}
readRDS(nfl4th_games_path())
}

fd_model <- function(){
if (probably_cran()) return(load_fd_model())
if (probably_cran() && !force_cache()) return(load_fd_model())
if (!file.exists(nfl4th_fdmodel_path())){
saveRDS(load_fd_model(), nfl4th_fdmodel_path())
}
readRDS(nfl4th_fdmodel_path())
}

wp_model <- function(){
if (probably_cran()) return(load_wp_model())
if (probably_cran() && !force_cache()) return(load_wp_model())
if (!file.exists(nfl4th_wpmodel_path())){
saveRDS(load_wp_model(), nfl4th_wpmodel_path())
}
Expand Down Expand Up @@ -64,3 +64,8 @@ probably_cran <- function(){
)
!is.na(cpu_threshold)
}

# allow user to force the cache even if probably_cran() is TRUE
force_cache <- function() {
getOption("nfl4th.force_cache", "false") == "true"
}

0 comments on commit 9a0222a

Please sign in to comment.