Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change default max cache size #18

Merged
merged 2 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions R/cache.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ relic_cache_delete <- function() {
#' `options("relic.cache.max.age")`, which take numeric time in days or a
#' string with units, e.g., "1 day" or "2 weeks".
#' @param max_size The maximum size of the cache, as a string that can be parsed
#' by [fs::fs_bytes()]. Defaults to "20 MB". Can be set with the environment
#' by [fs::fs_bytes()]. Defaults to "100 GB". Can be set with the environment
#' variable `RELIC_CACHE_MAX_SIZE` or `options("relic.cache.max.size")`.
#' Cached files will be deleted from oldest to youngest until the cache size
#' is under this limit.
Expand Down Expand Up @@ -84,7 +84,7 @@ relic_cache_max_size <- function() {
fs_bytes(Sys.getenv(
"RELIC_CACHE_MAX_SIZE",
getOption("relic.cache.max.size",
default = "20 MB"
default = "100 GB"
)
))
}
Expand Down
52 changes: 32 additions & 20 deletions R/tar_read_version.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,49 +54,61 @@ tar_read_raw_version <- function(name, ref = "HEAD", repo = ".", store = NULL) {
}

target <- switch(record$repository,
local = read_target_aws(record, path_store = path_store),
aws = read_target_aws(record, path_store = path_store),
abort("Unknown targets repository type: ", record$repository)
local = read_target_aws(record),
aws = read_target_aws(record),
abort("Unknown targets repository type: ", record$repository)
)

target
}

read_target_aws <- function(record, path_store) {
read_target_aws <- function(record) {
aws_loc <- aws_loc_from_meta_path(record$path[[1]])
local_target_path <- get_file_version(
path = aws_loc$key, ref = aws_loc$version,
repo = paste0("s3://", aws_loc$bucket),
endpoint = aws_loc$endpoint, region = aws_loc$region
)
record_local <- record
record_local$path <- list(local_target_path)
record_local$repository <- "local"
targets::tar_read_raw(record_local$name,
meta = record_local,
store = path_dir(path_dir(local_target_path))
)
if (record$format == "file") {
return(local_target_path)
} else {
record_local <- record
record_local$path <- NA
record_local$repository <- "local"
temp_store <- path_dir(dir_create(path(file_temp("_targets"), "objects")))
link_create(local_target_path, path(temp_store, "objects", path_file(local_target_path)))
on.exit(dir_delete(temp_store))
return(targets::tar_read_raw(record_local$name,
meta = record_local,
store = temp_store))
}
}

read_target_local <- function(record, path_store) {
read_target_local <- function(record) {
# For local targets
local_target_path <- get_file_version(
path = record$path[[1]], ref = record$version,
repo = record$repository
)
record_local <- record
record_local$path <- list(local_target_path)

targets::tar_read_raw(record_local$name,
meta = record_local,
store = path_store
)
if (record$format == "file") {
return(local_target_path)
} else {
record_local <- record
record_local$path <- NA
record_local$repository <- "local"
temp_store <- path_dir(dir_create(path(file_temp("_targets"), "objects")))
link_create(local_target_path, path(temp_store, "objects", path_file(local_target_path)))
on.exit(dir_delete(temp_store))
return(targets::tar_read_raw(record_local$name,
meta = record_local,
store = temp_store))
}
}

aws_loc_from_meta_path <- function(path) {
splits <- strsplit(path, "=")
aws_loc <- structure(lapply(splits, function(x) x[[2]]),
.Names = vapply(splits, function(x) x[[1]], character(1))
.Names = vapply(splits, function(x) x[[1]], character(1))
)
if (!is.null(aws_loc$endpoint)) {
aws_loc$endpoint <- rawToChar(openssl::base64_decode(aws_loc$endpoint))
Expand Down