# objects preparation
cacheRepo <- tempdir()
createEmptyRepo( cacheRepo )
fun <- function(n) {replicate(n, summary(lm(Sepal.Length~Species, iris))$r.squared)}
system.time( res <- cache(cacheRepo, fun, 1000) )
system.time( res <- cache(cacheRepo, fun, 1000) )
testFun <- function(x) {cat(x);x}
# will be executed
tmp <- cache(cacheRepo, testFun, "Say hallo!")
# will loaded from repository
tmp <- cache(cacheRepo, testFun, "Say hallo!")
# will be executed, fails with expiration date
tmp <- cache(cacheRepo, testFun, "Say hallo!", notOlderThan = now())
# will be executed, passes with expiration date [within hour]
tmp <- cache(cacheRepo, testFun, "Say hallo!", notOlderThan = now() - hours(1))
deleteRepo( cacheRepo )
rm( cacheRepo )
Run the code above in your browser using DataCamp Workspace