This implements one possible cache function for use in getFileMetadata and friends. Caching is based on BiocFileCache with thread-safety enforced by filelock.

biocCache(cache, key, save, update = FALSE)

Arguments

cache

A BiocFileCache object.

key, save

See getFileMetadata for details on the caching function.

update

Logical scalar indicating whether assets in the cache should be forcibly updated. Useful for resolving corrupted caches or incomplete downloads.

Value

String containing a path to the cached resource inside cache.

See also

getFileMetadata for more details on the caching function.

Author

Aaron Lun

Examples

library(BiocFileCache)
#> Loading required package: dbplyr
tmp <- tempfile()
bfc <- BiocFileCache(tmp, ask=FALSE)
cache.fun <- function(key, save) biocCache(bfc, key, save)

# First query hits the cache:
getFile(example.id, example.url, cache = cache.fun)
#> [1] "/tmp/RtmpqT1SXc/file7341c314d15/734c948460_734c948460"

# Second query re-uses the cache:
getFile(example.id, example.url, cache = cache.fun)
#> [1] "/tmp/RtmpqT1SXc/file7341c314d15/734c948460_734c948460"