Learn R Programming

SpaDES (version 1.2.0)

cache: Cache method for simList class objects

Description

Because the simList has an environment as one of its slots, the caching mechanism of the archivist package does not work. Here, we make a slight tweak to the cache function. Specifically, we remove all elements that have an environment as part of their attributes. This is generally functions that are loaded from the modules, but also the .envir slot in the simList. Thus, only non-function objects are used as part of the digest call in the digest package (used internally in the cache function).

Usage

cache(cacheRepo = NULL, FUN, ..., notOlderThan = NULL)
"cache"(cacheRepo = NULL, FUN, ..., notOlderThan = NULL)

Arguments

cacheRepo
A repository used for storing cached objects.
FUN
A function to be called.
...
Arguments of FUN function .
notOlderThan
load an artifact from the database only if it was created after notOlderThan.

Value

Identical to cache

See Also

cache.

Examples

Run this code
## Not run: 
# times <- list(start=0, end=10)
# params <- list(dummy = 1)
# mySim <- simInit(times = times, params = params)
# if (require(archivist)) {
#   archivist::createLocalRepo(paths(mySim)$cachePath)
#   system.time(outSim <- cache(paths(mySim)$cachePath, spades, sim = mySim))
# 
#   # will be cached now, to be sure inputs are identical,
#   #   mySim should be put back to original state
#   mySim <- simInit(times = times)
#   system.time(outSim <- cache(paths(mySim)$cachePath, spades, sim = mySim))
#   # compare
#   system.time(outSim2 <- spades(mySim))
# }
# ## End(Not run)

Run the code above in your browser using DataLab