Skip to content

Commit

Permalink
fixup! refactor(cache): use saveRDS/readRDS instead of makeLazyLoadDB…
Browse files Browse the repository at this point in the history
…/lazyload
  • Loading branch information
atusy committed Apr 27, 2024
1 parent a0dc112 commit 259fdd5
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions R/cache.R
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ new_cache = function() {
cache_exists = function(hash, lazy = TRUE) {
if (!is.character(hash)) return(FALSE)
path = cache_path(hash)
if (!lazy) return(file.exists(path, 'Rdata', sep = '.'))
if (!lazy) return(file.exists(paste(path, 'RData', sep = '.')))

# for backward compatibility, allow rdb/rdx
file.exists(paste(path, 'rds', sep = '.')) || all(file.exists(paste(path, c('rdb', 'rdx', sep = '.'))))
file.exists(paste(path, 'rds', sep = '.')) || all(file.exists(paste(path, c('rdb', 'rdx'), sep = '.')))
}

# when cache=3, code output is stored in .[hash], so cache=TRUE won't lose
Expand Down Expand Up @@ -151,7 +151,7 @@ knit_cache_postprocess.default = function(x, ...) identity(x)
cache = new_cache()

# a regex for cache files
cache_rx = '_[abcdef0123456789]{32}[.](rdb|rdx|RData)$'
cache_rx = '_[abcdef0123456789]{32}[.](rds|rdb|rdx|RData)$'

#' Build automatic dependencies among chunks
#'
Expand Down Expand Up @@ -266,7 +266,7 @@ load_cache = function(
'Wrong cache databases for the chunk ', label,
'. You need to remove redundant cache files. Found ', paste(p2, collapse = ', ')
)
p2 = unique(gsub('[.](rdb|rdx|RData)$', '', p2))
p2 = unique(gsub('[.](rds|rdb|rdx|RData)$', '', p2))
if (length(p2) != 1) stop('Cannot identify the cache database for chunk ', label)
cache$load(file.path(p0, p2), lazy)
if (missing(object)) return(invisible(NULL))
Expand Down

0 comments on commit 259fdd5

Please sign in to comment.