@@ -93,18 +93,25 @@ ensure_cache_dir_exists = function() {
9393
9494clear_cache_by_time = function () {
9595 cache_dir = tools :: R_user_dir(" ffanalytics" , " cache" )
96+
97+ # First checking for all files older than 8 hours
9698 file_names = list.files(cache_dir , full.names = TRUE )
9799
98100 if (length(file_names ) == 0 ) {
99101 return (NULL )
100102 }
101-
102103 file_mtimes = file.mtime(file_names )
103- files_to_clear = difftime(Sys.time(), file_mtimes , units = " hours" ) > 8
104+ all_files_to_clear = difftime(Sys.time(), file_mtimes , units = " hours" ) > 8
105+ scrapes_to_clear = grepl(" _scrape" , basename(file_names ), fixed = TRUE ) &
106+ difftime(Sys.time(), file_mtimes , units = " hours" ) > 1
107+
108+ files_to_clear = as.logical(pmax(all_files_to_clear , scrapes_to_clear ))
109+
104110
105111 if (any(files_to_clear , na.rm = TRUE )) {
106112 file.remove(file_names [files_to_clear ])
107113 }
114+
108115}
109116
110117cache_file_names = c(
@@ -188,7 +195,8 @@ cache_file_names = c(
188195 " ecr_draft_db_ppr.rds" = " ECR Draft DB PPR" ,
189196 " ecr_weekly_db_std.rds" = " ECR Weekly DB Std" ,
190197 " ecr_weekly_db_half.rds" = " ECR Weekly DB Half" ,
191- " ecr_weekly_db_ppr.rds" = " ECR Weekly DB PPR"
198+ " ecr_weekly_db_ppr.rds" = " ECR Weekly DB PPR" ,
199+ " cbs_scrape.rds" = " CBS Scrape"
192200)
193201
194202
0 commit comments