dazcache is a persistent disk cache that every R process on one machine can share: values outlive the session, expire, carry tags and stay under a size limit.
- Sessions, scheduled jobs and parallel workers use one cache at once, over a local filesystem. Reads never wait, and each write is atomic, alone or in a transaction. It is built on libmdbx, through the mdbx package.
- A key can be a string, a date, a named list or a mix of these, written in a fixed text encoding, so the same values find the same entry in every session.
- Values of 32 KiB or more (by default) become read-only RDS files named by their content, stored once however many keys hold them, and readable in place by other tools.
Installation
install.packages("dazcache")The development version is on GitHub:
# install.packages("pak")
pak::pak("pedrobtz/dazcache")Usage
A cache is a directory. Open one, store a value for an hour (3600 seconds), and read it back:
library(dazcache)
s <- cache(file.path(tempdir(), "prices"))
cache_set(s, "XSWX/2026-08-29", c(101.2, 101.9), expire = 3600)
cache_get(s, "XSWX/2026-08-29")
#> [1] 101.2 101.9A key with no entry is an error, unless you say what to return instead:
cache_get(s, "XNYS/2026-08-29", default = NULL)
#> NULLdazcache also memoises functions, drops entries by tag and checks itself for damage; Get started shows how.
Learn more
- Get started: keys, expiry, tags, memoising and large values, through one example.
- Cache slow work: memoise a slow function, keep the files it downloads, and use the cache from memoise and Shiny.
- Operating a shared cache: many processes, transactions, durability, size limits and repair.
- How a cache stores keys and values: the directory, the files and the key encoding.
- Reference: every function.
dazcache follows the design of Python’s diskcache; for a cache that lives only in one session’s memory, cache_mem() from cachem is lighter.