Learn R Programming

bit64 (version 4.5.2)

cache: Atomic Caching

Description

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 cache
print(x, all.names = FALSE, pattern, ...)

Value

see details

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

passed to ls when listing the cache content

pattern

passed to ls when listing the cache content

...

ignored

Author

Jens Oehlschlägel <Jens.Oehlschlaegel@truecluster.com>

Details

A cache is an link{environment} attached to an atomic object with the link{attrib} 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. Function newcache(x) creates a new cache referencing x
Function jamcache(x) forces x to have a cache
Function cache(x) returns the cache attached to x if it is not found to be outdated
Function setcache(x, which, value) assigns a value into the cache of x
Function getcache(x, which) gets cache value 'which' from x
Function remcache removes the cache from x

See Also

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: na.count, nvalid, is.sorted, nunique and nties
Setting big caches with a relevant memory footprint requires a conscious decision of the user: hashcache, sortcache, ordercache and sortordercache
Functions that use big caches: match.integer64, %in%.integer64, duplicated.integer64, unique.integer64, unipos, table.integer64, as.factor.integer64, as.ordered.integer64, keypos, tiepos, rank.integer64, prank, qtile, quantile.integer64, median.integer64 and summary.integer64

Examples

Run this code
	x <- as.integer64(sample(c(rep(NA, 9), 1:9), 32, TRUE))
	y <- x
	still.identical(x,y)
	y[1] <- NA
	still.identical(x,y)
	mycache <- newcache(x)
	ls(mycache)
	mycache
	rm(mycache)
	jamcache(x)
	cache(x)
	x[1] <- NA
	cache(x)
	getcache(x, "abc")
	setcache(x, "abc", 1)
	getcache(x, "abc")
	remcache(x)
	cache(x)

Run the code above in your browser using DataLab