Functions for caching results attached to atomic objects
Usage
newcache(x)
jamcache(x)
cache(x)
setcache(x, which, value)
getcache(x, which)
remcache(x)
# S3 method for class 'cache'
print(x, all.names = FALSE, pattern, ...)
Arguments
- x
an integer64 vector (or a cache object in case of
print.cache
)- which
A character naming the object to be retrieved from the cache or to be stored in the cache
- value
An object to be stored in the cache
- all.names, pattern
passed to
ls()
when listing the cache content- ...
ignored
Details
A cache
is an environment
attached to an atomic object with the
attribute
name 'cache'. It contains at least a reference to the
atomic object that carries the cache. This is used when accessing
the cache to detect whether the object carrying the cache has been
modified meanwhile.
Functions
newcache()
: creates a new cache referencingx
jamcache()
: forcesx
to have a cachecache()
: returns the cache attached tox
if it is not found to be outdatedsetcache()
: assigns a value into the cache ofx
getcache()
: gets cache value 'which' fromx
remcache()
: removes the cache fromx
See also
bit::still.identical()
for testing whether to symbols point to the same RAM.
Functions that get and set small cache-content automatically when a cache is present:
bit::na.count()
, bit::nvalid()
, bit::is.sorted()
, bit::nunique()
and
bit::nties()
Setting big caches with a relevant memory footprint requires a conscious decision
of the user: hashcache
, sortcache
, ordercache
, sortordercache
Functions that use big caches: match.integer64()
, %in%.integer64
,
duplicated.integer64()
, unique.integer64()
, unipos()
, table.integer64()
,
keypos()
, tiepos()
, rank.integer64()
, prank()
, qtile()
,
quantile.integer64()
, median.integer64()
, and summary.integer64()
Examples
x <- as.integer64(sample(c(rep(NA, 9), 1:9), 32, TRUE))
y <- x
still.identical(x,y)
#> [1] TRUE
y[1] <- NA
still.identical(x,y)
#> [1] FALSE
mycache <- newcache(x)
ls(mycache)
#> [1] "x"
mycache
#> cache_integer64: x
rm(mycache)
jamcache(x)
#> cache_integer64: x
cache(x)
#> cache_integer64: x
x[1] <- NA
cache(x)
#> Warning: removed outdated cache
#> NULL
getcache(x, "abc")
#> NULL
setcache(x, "abc", 1)
#> cache_integer64: abc - x
getcache(x, "abc")
#> [1] 1
remcache(x)
cache(x)
#> NULL