SpaDES (version 1.3.1)

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).

showCache and clearCache are wrappers around archivist package functions, specific to simList objects. They allow the user a bit of control over what is being cached.

Usage

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

# S4 method for ANY cache(cacheRepo = NULL, FUN, ..., notOlderThan = NULL)

clearCache(sim, afterDate, beforeDate, cacheRepo, ...)

# S4 method for ANY clearCache(sim, afterDate, beforeDate, cacheRepo, ...)

showCache(sim, cacheRepo, ...)

# S4 method for ANY showCache(sim, cacheRepo, ...)

Arguments

cacheRepo

A repository used for storing cached objects.

FUN

A function to be called.

...

Other arguments passed to

If neither afterDate or beforeDate are provided, then all objects will be removed. If both afterDate and beforeDate are specified, then all objects between afterDate and beforeDate will be deleted.

notOlderThan

load an artifact from the database only if it was created after notOlderThan.

sim

A simList simulation object, generally produced by simInit.

afterDate

Objects cached after this date will be deleted, formatted YYYY-MM-DD.

beforeDate

Objects cached before this date will be deleted, formatted as YYYY-MM-DD.

Value

Identical to cache

Will clear all objects from the cachePath of the sim object

Details

Normally, a user will access this functionality as an argument in spades.

See Also

cache.

cache.

splitTagsLocal.

Examples

Run this code
# NOT RUN {
mySim <- simInit(times=list(start=0.0, end=5.0),
                 params=list(.globals=list(stackName="landscape", burnStats = "testStats")),
                 modules=list("randomLandscapes", "fireSpread"),
                 paths=list(modulePath=system.file("sampleModules", package="SpaDES")))
if (require(archivist)) {
  # Call cache function directly
  archivist::createLocalRepo(paths(mySim)$cachePath)
  system.time(outSim <- cache(paths(mySim)$cachePath,
              spades, sim = copy(mySim), .plotInitialTime = NA, notOlderThan = Sys.time()))
  system.time(outSim <- cache(paths(mySim)$cachePath,
              spades, sim = copy(mySim), .plotInitialTime = NA))

  # This functionality can be achieved within a spades call
  # compare caching ... run once to create cache
  system.time(outSim <- spades(copy(mySim), cache = TRUE, notOlderThan = Sys.time(),
                               .plotInitialTime = NA))
  # compare... second time is fast
  system.time(outSimCached <- spades(copy(mySim), cache = TRUE, .plotInitialTime = NA))
  all.equal(outSim, outSimCached)
}
# }
# NOT RUN {
# }
# NOT RUN {
clearCache(mySim)
# }
# NOT RUN {
showCache(mySim)
# }

Run the code above in your browser using DataLab