These are convenience wrappers around archivist package functions. They allow the user a bit of control over what is being cached.

clearCache(x, userTags = character(), after, before, ...)

# S4 method for ANY
clearCache(x, userTags, after, before,
  ask = getOption("reproducible.ask"), ...)

showCache(x, userTags = character(), after, before, ...)

# S4 method for ANY
showCache(x, userTags = character(), after, before, ...)

keepCache(x, userTags = character(), after, before, ask, ...)

# S4 method for ANY
keepCache(x, userTags = character(), after, before,
  ask = getOption("reproducible.ask"), ...)

Arguments

x

A simList or a directory containing a valid archivist repository

userTags

Character vector. If used, this will be used in place of the after and before. Specifying one or more userTag here will clear all objects that match those tags. Matching is via regular expression, meaning partial matches will work unless strict beginning (^) and end ($) of string characters are used. Matching will be against any of the 3 columns returned by showCache(), i.e., artifact, tagValue or tagName. Also, length userTags > 1, then matching is by `and`. For `or` matching, use | in a single character string. See examples.

If neither after or before are provided, nor userTags, then all objects will be removed. If both after and before are specified, then all objects between after and before will be deleted. If userTags is used, this will override after or before.

after

A time (POSIX, character understandable by data.table). Objects cached after this time will be shown or deleted.

before

A time (POSIX, character understandable by data.table). Objects cached before this time will be shown or deleted.

...

Other arguments. Currently, regexp, a logical, can be provided. This must be TRUE if the use is passing a regular expression. Otherwise, userTags will need to be exact matches. Default is missing, which is the same as TRUE. If there are errors due to regular expression problem, try FALSE.

ask

Logical. If FALSE, then it will not ask to confirm deletions using clearCache or keepCache. Default is TRUE

Value

Will clear all objects (or those that match userTags, or those between after or before) from the repository located at cachePath of the sim object, if sim is provided, or located in cacheRepo. Invisibly returns a data.table of the removed items.

Details

clearCache

remove items from the cache based on their userTag or times values.

keepCache

remove all cached items except those based on certain userTags or times values.

showCache

display the contents of the cache.

Note

If the cache is larger than 10MB, and clearCache is used, there will be a message and a pause, if interactive, to prevent accidentally deleting of a large cache repository.

See also

mergeCache, splitTagsLocal. Many more examples in Cache

Examples

library(raster) try(detach("package:magrittr", unload = TRUE), silent = TRUE) # magrittr, #if loaded, gives an error below tmpDir <- file.path(tempdir(), "reproducible_examples", "Cache") try(clearCache(tmpDir), silent = TRUE) # just to make sure it is clear # Basic use ranNumsA <- Cache(rnorm, 10, 16, cacheRepo = tmpDir) # All same ranNumsB <- Cache(rnorm, 10, 16, cacheRepo = tmpDir) # recovers cached copy
#> loading cached result from previous rnorm call, adding to memoised copy
ranNumsC <- rnorm(10, 16) %>% Cache(cacheRepo = tmpDir) # recovers cached copy
#> loading memoised result from previous 'rnorm' pipe sequence call.
ranNumsD <- Cache(quote(rnorm(n = 10, 16)), cacheRepo = tmpDir) # recovers cached copy
#> loading memoised result from previous rnorm call.
# Any minor change makes it different ranNumsE <- rnorm(10, 6) %>% Cache(cacheRepo = tmpDir) # different ## Example 1: basic cache use with tags ranNumsA <- Cache(rnorm, 4, cacheRepo = tmpDir, userTags = "objectName:a") ranNumsB <- Cache(runif, 4, cacheRepo = tmpDir, userTags = "objectName:b") ranNumsC <- Cache(runif, 40, cacheRepo = tmpDir, userTags = "objectName:b") showCache(tmpDir, userTags = c("objectName"))
#> Cache size:
#> Total (including Rasters): 1.4 Kb
#> Selected objects (not including Rasters): 840 bytes
#> artifact tagKey #> 1: 14b8897319b0308acbd84c07ef72f6c1 format #> 2: 14b8897319b0308acbd84c07ef72f6c1 name #> 3: 14b8897319b0308acbd84c07ef72f6c1 class #> 4: 14b8897319b0308acbd84c07ef72f6c1 date #> 5: 14b8897319b0308acbd84c07ef72f6c1 cacheId #> 6: 14b8897319b0308acbd84c07ef72f6c1 objectName #> 7: 14b8897319b0308acbd84c07ef72f6c1 function #> 8: 14b8897319b0308acbd84c07ef72f6c1 object.size #> 9: 14b8897319b0308acbd84c07ef72f6c1 accessed #> 10: 14b8897319b0308acbd84c07ef72f6c1 otherFunctions #> 11: 14b8897319b0308acbd84c07ef72f6c1 otherFunctions #> 12: 14b8897319b0308acbd84c07ef72f6c1 otherFunctions #> 13: 14b8897319b0308acbd84c07ef72f6c1 otherFunctions #> 14: 14b8897319b0308acbd84c07ef72f6c1 otherFunctions #> 15: 14b8897319b0308acbd84c07ef72f6c1 otherFunctions #> 16: 14b8897319b0308acbd84c07ef72f6c1 otherFunctions #> 17: 14b8897319b0308acbd84c07ef72f6c1 preDigest #> 18: 14b8897319b0308acbd84c07ef72f6c1 preDigest #> 19: 1c116f14cde81750bdef785a117715dc format #> 20: 1c116f14cde81750bdef785a117715dc name #> 21: 1c116f14cde81750bdef785a117715dc class #> 22: 1c116f14cde81750bdef785a117715dc date #> 23: 1c116f14cde81750bdef785a117715dc cacheId #> 24: 1c116f14cde81750bdef785a117715dc objectName #> 25: 1c116f14cde81750bdef785a117715dc function #> 26: 1c116f14cde81750bdef785a117715dc object.size #> 27: 1c116f14cde81750bdef785a117715dc accessed #> 28: 1c116f14cde81750bdef785a117715dc otherFunctions #> 29: 1c116f14cde81750bdef785a117715dc otherFunctions #> 30: 1c116f14cde81750bdef785a117715dc otherFunctions #> 31: 1c116f14cde81750bdef785a117715dc otherFunctions #> 32: 1c116f14cde81750bdef785a117715dc otherFunctions #> 33: 1c116f14cde81750bdef785a117715dc otherFunctions #> 34: 1c116f14cde81750bdef785a117715dc otherFunctions #> 35: 1c116f14cde81750bdef785a117715dc preDigest #> 36: 1c116f14cde81750bdef785a117715dc preDigest #> 37: 50157d578376153c28c9b75577b25cb6 format #> 38: 50157d578376153c28c9b75577b25cb6 name #> 39: 50157d578376153c28c9b75577b25cb6 class #> 40: 50157d578376153c28c9b75577b25cb6 date #> 41: 50157d578376153c28c9b75577b25cb6 cacheId #> 42: 50157d578376153c28c9b75577b25cb6 objectName #> 43: 50157d578376153c28c9b75577b25cb6 function #> 44: 50157d578376153c28c9b75577b25cb6 object.size #> 45: 50157d578376153c28c9b75577b25cb6 accessed #> 46: 50157d578376153c28c9b75577b25cb6 otherFunctions #> 47: 50157d578376153c28c9b75577b25cb6 otherFunctions #> 48: 50157d578376153c28c9b75577b25cb6 otherFunctions #> 49: 50157d578376153c28c9b75577b25cb6 otherFunctions #> 50: 50157d578376153c28c9b75577b25cb6 otherFunctions #> 51: 50157d578376153c28c9b75577b25cb6 otherFunctions #> 52: 50157d578376153c28c9b75577b25cb6 otherFunctions #> 53: 50157d578376153c28c9b75577b25cb6 preDigest #> 54: 50157d578376153c28c9b75577b25cb6 preDigest #> artifact tagKey #> tagValue createdDate #> 1: rda 2018-09-11 17:26:41 #> 2: 14b8897319b0308acbd84c07ef72f6c1 2018-09-11 17:26:41 #> 3: numeric 2018-09-11 17:26:41 #> 4: 2018-09-11 17:26:41 2018-09-11 17:26:41 #> 5: 7cb09aa387ba235db013863648303b34 2018-09-11 17:26:41 #> 6: b 2018-09-11 17:26:41 #> 7: runif 2018-09-11 17:26:41 #> 8: 1024 2018-09-11 17:26:41 #> 9: 2018-09-11 17:26:41 2018-09-11 17:26:41 #> 10: withCallingHandlers 2018-09-11 17:26:41 #> 11: saveRDS 2018-09-11 17:26:41 #> 12: do.call 2018-09-11 17:26:41 #> 13: build_site_local 2018-09-11 17:26:41 #> 14: build_reference 2018-09-11 17:26:41 #> 15: data_reference_topic 2018-09-11 17:26:41 #> 16: try 2018-09-11 17:26:41 #> 17: n:c1de94a5a8d2a5813e07152fb7ea2038 2018-09-11 17:26:41 #> 18: .FUN:179092fbad3ec261e58bc89bc8a703c3 2018-09-11 17:26:41 #> 19: rda 2018-09-11 17:26:41 #> 20: 1c116f14cde81750bdef785a117715dc 2018-09-11 17:26:41 #> 21: numeric 2018-09-11 17:26:41 #> 22: 2018-09-11 17:26:41 2018-09-11 17:26:41 #> 23: c540fe4e542ac025a1cb8dff2755fc7f 2018-09-11 17:26:41 #> 24: b 2018-09-11 17:26:41 #> 25: runif 2018-09-11 17:26:41 #> 26: 1312 2018-09-11 17:26:41 #> 27: 2018-09-11 17:26:41 2018-09-11 17:26:41 #> 28: withCallingHandlers 2018-09-11 17:26:41 #> 29: saveRDS 2018-09-11 17:26:41 #> 30: do.call 2018-09-11 17:26:41 #> 31: build_site_local 2018-09-11 17:26:41 #> 32: build_reference 2018-09-11 17:26:41 #> 33: data_reference_topic 2018-09-11 17:26:41 #> 34: try 2018-09-11 17:26:41 #> 35: n:c42c56d63e6a88c428b18dee0f4489d7 2018-09-11 17:26:41 #> 36: .FUN:179092fbad3ec261e58bc89bc8a703c3 2018-09-11 17:26:41 #> 37: rda 2018-09-11 17:26:40 #> 38: 50157d578376153c28c9b75577b25cb6 2018-09-11 17:26:40 #> 39: numeric 2018-09-11 17:26:40 #> 40: 2018-09-11 17:26:40 2018-09-11 17:26:40 #> 41: f55d44974d91fbf61b6cb524983b1ebc 2018-09-11 17:26:41 #> 42: a 2018-09-11 17:26:41 #> 43: rnorm 2018-09-11 17:26:41 #> 44: 1024 2018-09-11 17:26:41 #> 45: 2018-09-11 17:26:40 2018-09-11 17:26:41 #> 46: withCallingHandlers 2018-09-11 17:26:41 #> 47: saveRDS 2018-09-11 17:26:41 #> 48: do.call 2018-09-11 17:26:41 #> 49: build_site_local 2018-09-11 17:26:41 #> 50: build_reference 2018-09-11 17:26:41 #> 51: data_reference_topic 2018-09-11 17:26:41 #> 52: try 2018-09-11 17:26:41 #> 53: n:c1de94a5a8d2a5813e07152fb7ea2038 2018-09-11 17:26:41 #> 54: .FUN:a979d0700a6ef8c7c18736096ff1d522 2018-09-11 17:26:41 #> tagValue createdDate
showCache(tmpDir, userTags = c("^a$")) # regular expression ... "a" exactly
#> Cache size:
#> Total (including Rasters): 1.4 Kb
#> Selected objects (not including Rasters): 256 bytes
#> artifact tagKey #> 1: 50157d578376153c28c9b75577b25cb6 format #> 2: 50157d578376153c28c9b75577b25cb6 name #> 3: 50157d578376153c28c9b75577b25cb6 class #> 4: 50157d578376153c28c9b75577b25cb6 date #> 5: 50157d578376153c28c9b75577b25cb6 cacheId #> 6: 50157d578376153c28c9b75577b25cb6 objectName #> 7: 50157d578376153c28c9b75577b25cb6 function #> 8: 50157d578376153c28c9b75577b25cb6 object.size #> 9: 50157d578376153c28c9b75577b25cb6 accessed #> 10: 50157d578376153c28c9b75577b25cb6 otherFunctions #> 11: 50157d578376153c28c9b75577b25cb6 otherFunctions #> 12: 50157d578376153c28c9b75577b25cb6 otherFunctions #> 13: 50157d578376153c28c9b75577b25cb6 otherFunctions #> 14: 50157d578376153c28c9b75577b25cb6 otherFunctions #> 15: 50157d578376153c28c9b75577b25cb6 otherFunctions #> 16: 50157d578376153c28c9b75577b25cb6 otherFunctions #> 17: 50157d578376153c28c9b75577b25cb6 preDigest #> 18: 50157d578376153c28c9b75577b25cb6 preDigest #> tagValue createdDate #> 1: rda 2018-09-11 17:26:40 #> 2: 50157d578376153c28c9b75577b25cb6 2018-09-11 17:26:40 #> 3: numeric 2018-09-11 17:26:40 #> 4: 2018-09-11 17:26:40 2018-09-11 17:26:40 #> 5: f55d44974d91fbf61b6cb524983b1ebc 2018-09-11 17:26:41 #> 6: a 2018-09-11 17:26:41 #> 7: rnorm 2018-09-11 17:26:41 #> 8: 1024 2018-09-11 17:26:41 #> 9: 2018-09-11 17:26:40 2018-09-11 17:26:41 #> 10: withCallingHandlers 2018-09-11 17:26:41 #> 11: saveRDS 2018-09-11 17:26:41 #> 12: do.call 2018-09-11 17:26:41 #> 13: build_site_local 2018-09-11 17:26:41 #> 14: build_reference 2018-09-11 17:26:41 #> 15: data_reference_topic 2018-09-11 17:26:41 #> 16: try 2018-09-11 17:26:41 #> 17: n:c1de94a5a8d2a5813e07152fb7ea2038 2018-09-11 17:26:41 #> 18: .FUN:a979d0700a6ef8c7c18736096ff1d522 2018-09-11 17:26:41
# Fine control of cache elements -- pick out only the large runif object, and remove it cache1 <- showCache(tmpDir, userTags = c("runif")) # show only cached objects made during runif
#> Cache size:
#> Total (including Rasters): 1.4 Kb
#> Selected objects (not including Rasters): 584 bytes
toRemove <- cache1[tagKey=="object.size"][as.numeric(tagValue) > 700]$artifact clearCache(tmpDir, userTags = toRemove)
#> Cache size:
#> Total (including Rasters): 1.4 Kb
#> Selected objects (not including Rasters): 0 bytes
cacheAfter <- showCache(tmpDir, userTags = c("runif")) # Only the small one is left
#> Cache size:
#> Total (including Rasters): 1.4 Kb
#> Selected objects (not including Rasters): 584 bytes