Skip to content

Commit

Permalink
cache everything to disc #133 opems #236
Browse files Browse the repository at this point in the history
  • Loading branch information
maxheld83 committed Apr 21, 2021
1 parent 4a73de4 commit 2583b53
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ Imports:
vctrs,
memoise,
promises,
future
future,
cachem
Suggests:
testthat,
subugoetheme,
Expand Down
4 changes: 2 additions & 2 deletions R/pretest.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ tabulate_metacheckable <- function(x, ...) {
# https://github.com/subugoe/metacheck/issues/169
`unique` = lazily(purrr::negate(duplicated))(x, `not_missing`),
`within_limits` = lazily(is_in_limit, ...)(x, `unique`),
`doi_org_found` = lazily(biblids::is_doi_found)(x, `within_limits`),
`from_cr` = lazily(biblids::is_doi_from_ra, "Crossref")(x, `doi_org_found`),
`doi_org_found` = lazily(memoised_is_doi_found)(x, `within_limits`),
`from_cr` = lazily(memoised_is_doi_from_ra, "Crossref")(x, `doi_org_found`),
# should singl header first https://github.com/subugoe/metacheck/issues/176
`cr_md` = lazily(is_doi_cr_md)(x, `from_cr`),
`article` = lazily(is_doi_cr_type, "journal-article")(x, `cr_md`),
Expand Down
38 changes: 36 additions & 2 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,39 @@
.onLoad <- function(libname, pkgname) {
# for details see import.R
memoised_cr_works <<- memoise::memoise(insistently_cr_works)
memoised_possibly_cr_works_field <<- memoise::memoise(possibly_cr_works_field)
memoised_cr_works <<- memoise::memoise(
insistently_cr_works,
cache = cache_api()
)
memoised_possibly_cr_works_field <<- memoise::memoise(
possibly_cr_works_field,
cache = cache_api()
)
# also cache biblids calls to disc if possible
# pretty bad hack, because this makes it double memoised
memoised_is_doi_found <<- memoise::memoise(
biblids::is_doi_found,
cache = cache_api()
)
memoised_is_doi_from_ra <<- memoise::memoise(
biblids::is_doi_from_ra,
cache = cache_api()
)
}

#' Conditionally set a cache which can be reused across sessions
#' Helpful for testing, vignettes, etc.
#' @noRd
cache_api <- function() {
# TODO this should be removed when using BigQuery
# https://github.com/subugoe/metacheck/issues/236
if (fs::dir_exists("~")) {
# this should only work on unix compliant systems
cachem::cache_disk(
dir = "~/.metacheck-cache",
max_age = 60 * 60 * 24 * 31,
destroy_on_finalize = FALSE
)
} else {
cachem::cache_mem()
}
}

0 comments on commit 2583b53

Please sign in to comment.