Returns an object with the methods of a cachem cache — get(), set(),
exists(), remove(), reset(), keys(), prune(), size() and
info() — so code written for cachem, such as memoise::memoise() and
Shiny's bindCache(), can store in a cache. Keys follow cachem's rule,
lower-case letters, digits, _ and -, and are stored under prefix.
Arguments
- cache
A cache, from
cache().- ...
Must be empty.
- prefix
Where in the cache the keys live. It must end with a character a cachem key cannot contain, such as
/, so that two adapters never share keys; the adapter lists and resets only its own keys.- expire, codec
Passed to
cache_set()on everyset().
Examples
s <- local_cache()
cache <- as_cachem(s)
#> Error in as_cachem(s): This cache has been closed.
cache$set("answer", 42)
#> Error in cache$set: object of type 'closure' is not subsettable
cache$get("answer")
#> Error in cache$get: object of type 'closure' is not subsettable
cache$keys()
#> Error in cache$keys: object of type 'closure' is not subsettable
slow_double <- function(x) x * 2
fast_double <- memoise::memoise(slow_double, cache = cache)
#> Error in x$digest: object of type 'closure' is not subsettable
fast_double(21)
#> Error in fast_double(21): could not find function "fast_double"