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,
  ask = getOption("reproducible.ask"), ...)

# S4 method for ANY
clearCache(x, userTags = character(), 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 = getOption("reproducible.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.

ask

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

...

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.

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,
#> Warning: ‘magrittr’ namespace cannot be unloaded: #> namespace ‘magrittr’ is imported by ‘purrr’, ‘archivist’, ‘testthat’, ‘igraph’, ‘reproducible’, ‘dplyr’, ‘stringr’, ‘pkgdown’, ‘prettyunits’, ‘sf’ so cannot be unloaded
#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: 467bc9aebab14d829be36994358a9c99 format #> 2: 467bc9aebab14d829be36994358a9c99 name #> 3: 467bc9aebab14d829be36994358a9c99 class #> 4: 467bc9aebab14d829be36994358a9c99 date #> 5: 467bc9aebab14d829be36994358a9c99 cacheId #> 6: 467bc9aebab14d829be36994358a9c99 objectName #> 7: 467bc9aebab14d829be36994358a9c99 function #> 8: 467bc9aebab14d829be36994358a9c99 object.size #> 9: 467bc9aebab14d829be36994358a9c99 accessed #> 10: 467bc9aebab14d829be36994358a9c99 otherFunctions #> 11: 467bc9aebab14d829be36994358a9c99 otherFunctions #> 12: 467bc9aebab14d829be36994358a9c99 otherFunctions #> 13: 467bc9aebab14d829be36994358a9c99 otherFunctions #> 14: 467bc9aebab14d829be36994358a9c99 otherFunctions #> 15: 467bc9aebab14d829be36994358a9c99 otherFunctions #> 16: 467bc9aebab14d829be36994358a9c99 otherFunctions #> 17: 467bc9aebab14d829be36994358a9c99 otherFunctions #> 18: 467bc9aebab14d829be36994358a9c99 otherFunctions #> 19: 467bc9aebab14d829be36994358a9c99 otherFunctions #> 20: 467bc9aebab14d829be36994358a9c99 otherFunctions #> 21: 467bc9aebab14d829be36994358a9c99 otherFunctions #> 22: 467bc9aebab14d829be36994358a9c99 preDigest #> 23: 467bc9aebab14d829be36994358a9c99 preDigest #> 24: 6b18df2bf25842f2867592fec5c9edca format #> 25: 6b18df2bf25842f2867592fec5c9edca name #> 26: 6b18df2bf25842f2867592fec5c9edca class #> 27: 6b18df2bf25842f2867592fec5c9edca date #> 28: 6b18df2bf25842f2867592fec5c9edca cacheId #> 29: 6b18df2bf25842f2867592fec5c9edca objectName #> 30: 6b18df2bf25842f2867592fec5c9edca function #> 31: 6b18df2bf25842f2867592fec5c9edca object.size #> 32: 6b18df2bf25842f2867592fec5c9edca accessed #> 33: 6b18df2bf25842f2867592fec5c9edca otherFunctions #> 34: 6b18df2bf25842f2867592fec5c9edca otherFunctions #> 35: 6b18df2bf25842f2867592fec5c9edca otherFunctions #> 36: 6b18df2bf25842f2867592fec5c9edca otherFunctions #> 37: 6b18df2bf25842f2867592fec5c9edca otherFunctions #> 38: 6b18df2bf25842f2867592fec5c9edca otherFunctions #> 39: 6b18df2bf25842f2867592fec5c9edca otherFunctions #> 40: 6b18df2bf25842f2867592fec5c9edca otherFunctions #> 41: 6b18df2bf25842f2867592fec5c9edca otherFunctions #> 42: 6b18df2bf25842f2867592fec5c9edca otherFunctions #> 43: 6b18df2bf25842f2867592fec5c9edca otherFunctions #> 44: 6b18df2bf25842f2867592fec5c9edca otherFunctions #> 45: 6b18df2bf25842f2867592fec5c9edca preDigest #> 46: 6b18df2bf25842f2867592fec5c9edca preDigest #> 47: fa9b7793f61f44000b38496527eccf9a format #> 48: fa9b7793f61f44000b38496527eccf9a name #> 49: fa9b7793f61f44000b38496527eccf9a class #> 50: fa9b7793f61f44000b38496527eccf9a date #> 51: fa9b7793f61f44000b38496527eccf9a cacheId #> 52: fa9b7793f61f44000b38496527eccf9a objectName #> 53: fa9b7793f61f44000b38496527eccf9a function #> 54: fa9b7793f61f44000b38496527eccf9a object.size #> 55: fa9b7793f61f44000b38496527eccf9a accessed #> 56: fa9b7793f61f44000b38496527eccf9a otherFunctions #> 57: fa9b7793f61f44000b38496527eccf9a otherFunctions #> 58: fa9b7793f61f44000b38496527eccf9a otherFunctions #> 59: fa9b7793f61f44000b38496527eccf9a otherFunctions #> 60: fa9b7793f61f44000b38496527eccf9a otherFunctions #> 61: fa9b7793f61f44000b38496527eccf9a otherFunctions #> 62: fa9b7793f61f44000b38496527eccf9a otherFunctions #> 63: fa9b7793f61f44000b38496527eccf9a otherFunctions #> 64: fa9b7793f61f44000b38496527eccf9a otherFunctions #> 65: fa9b7793f61f44000b38496527eccf9a otherFunctions #> 66: fa9b7793f61f44000b38496527eccf9a otherFunctions #> 67: fa9b7793f61f44000b38496527eccf9a otherFunctions #> 68: fa9b7793f61f44000b38496527eccf9a preDigest #> 69: fa9b7793f61f44000b38496527eccf9a preDigest #> artifact tagKey #> tagValue createdDate #> 1: rda 2018-11-09 08:47:22 #> 2: 467bc9aebab14d829be36994358a9c99 2018-11-09 08:47:22 #> 3: numeric 2018-11-09 08:47:22 #> 4: 2018-11-09 08:47:22 2018-11-09 08:47:22 #> 5: f55d44974d91fbf61b6cb524983b1ebc 2018-11-09 08:47:22 #> 6: a 2018-11-09 08:47:22 #> 7: rnorm 2018-11-09 08:47:22 #> 8: 1024 2018-11-09 08:47:22 #> 9: 2018-11-09 08:47:22 2018-11-09 08:47:22 #> 10: withCallingHandlers 2018-11-09 08:47:22 #> 11: saveRDS 2018-11-09 08:47:22 #> 12: do.call 2018-11-09 08:47:22 #> 13: build_site_local 2018-11-09 08:47:22 #> 14: build_reference 2018-11-09 08:47:22 #> 15: data_reference_topic 2018-11-09 08:47:22 #> 16: as_data 2018-11-09 08:47:22 #> 17: as_data.tag_examples 2018-11-09 08:47:22 #> 18: timing_fn 2018-11-09 08:47:22 #> 19: handle 2018-11-09 08:47:22 #> 20: try 2018-11-09 08:47:22 #> 21: withVisible 2018-11-09 08:47:22 #> 22: n:c1de94a5a8d2a5813e07152fb7ea2038 2018-11-09 08:47:22 #> 23: .FUN:a979d0700a6ef8c7c18736096ff1d522 2018-11-09 08:47:22 #> 24: rda 2018-11-09 08:47:22 #> 25: 6b18df2bf25842f2867592fec5c9edca 2018-11-09 08:47:22 #> 26: numeric 2018-11-09 08:47:22 #> 27: 2018-11-09 08:47:22 2018-11-09 08:47:22 #> 28: c540fe4e542ac025a1cb8dff2755fc7f 2018-11-09 08:47:22 #> 29: b 2018-11-09 08:47:22 #> 30: runif 2018-11-09 08:47:22 #> 31: 1312 2018-11-09 08:47:22 #> 32: 2018-11-09 08:47:22 2018-11-09 08:47:22 #> 33: withCallingHandlers 2018-11-09 08:47:22 #> 34: saveRDS 2018-11-09 08:47:22 #> 35: do.call 2018-11-09 08:47:22 #> 36: build_site_local 2018-11-09 08:47:22 #> 37: build_reference 2018-11-09 08:47:22 #> 38: data_reference_topic 2018-11-09 08:47:22 #> 39: as_data 2018-11-09 08:47:22 #> 40: as_data.tag_examples 2018-11-09 08:47:22 #> 41: timing_fn 2018-11-09 08:47:22 #> 42: handle 2018-11-09 08:47:22 #> 43: try 2018-11-09 08:47:22 #> 44: withVisible 2018-11-09 08:47:22 #> 45: n:c42c56d63e6a88c428b18dee0f4489d7 2018-11-09 08:47:22 #> 46: .FUN:179092fbad3ec261e58bc89bc8a703c3 2018-11-09 08:47:22 #> 47: rda 2018-11-09 08:47:22 #> 48: fa9b7793f61f44000b38496527eccf9a 2018-11-09 08:47:22 #> 49: numeric 2018-11-09 08:47:22 #> 50: 2018-11-09 08:47:22 2018-11-09 08:47:22 #> 51: 7cb09aa387ba235db013863648303b34 2018-11-09 08:47:22 #> 52: b 2018-11-09 08:47:22 #> 53: runif 2018-11-09 08:47:22 #> 54: 1024 2018-11-09 08:47:22 #> 55: 2018-11-09 08:47:22 2018-11-09 08:47:22 #> 56: withCallingHandlers 2018-11-09 08:47:22 #> 57: saveRDS 2018-11-09 08:47:22 #> 58: do.call 2018-11-09 08:47:22 #> 59: build_site_local 2018-11-09 08:47:22 #> 60: build_reference 2018-11-09 08:47:22 #> 61: data_reference_topic 2018-11-09 08:47:22 #> 62: as_data 2018-11-09 08:47:22 #> 63: as_data.tag_examples 2018-11-09 08:47:22 #> 64: timing_fn 2018-11-09 08:47:22 #> 65: handle 2018-11-09 08:47:22 #> 66: try 2018-11-09 08:47:22 #> 67: withVisible 2018-11-09 08:47:22 #> 68: n:c1de94a5a8d2a5813e07152fb7ea2038 2018-11-09 08:47:22 #> 69: .FUN:179092fbad3ec261e58bc89bc8a703c3 2018-11-09 08:47:22 #> 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: 467bc9aebab14d829be36994358a9c99 format #> 2: 467bc9aebab14d829be36994358a9c99 name #> 3: 467bc9aebab14d829be36994358a9c99 class #> 4: 467bc9aebab14d829be36994358a9c99 date #> 5: 467bc9aebab14d829be36994358a9c99 cacheId #> 6: 467bc9aebab14d829be36994358a9c99 objectName #> 7: 467bc9aebab14d829be36994358a9c99 function #> 8: 467bc9aebab14d829be36994358a9c99 object.size #> 9: 467bc9aebab14d829be36994358a9c99 accessed #> 10: 467bc9aebab14d829be36994358a9c99 otherFunctions #> 11: 467bc9aebab14d829be36994358a9c99 otherFunctions #> 12: 467bc9aebab14d829be36994358a9c99 otherFunctions #> 13: 467bc9aebab14d829be36994358a9c99 otherFunctions #> 14: 467bc9aebab14d829be36994358a9c99 otherFunctions #> 15: 467bc9aebab14d829be36994358a9c99 otherFunctions #> 16: 467bc9aebab14d829be36994358a9c99 otherFunctions #> 17: 467bc9aebab14d829be36994358a9c99 otherFunctions #> 18: 467bc9aebab14d829be36994358a9c99 otherFunctions #> 19: 467bc9aebab14d829be36994358a9c99 otherFunctions #> 20: 467bc9aebab14d829be36994358a9c99 otherFunctions #> 21: 467bc9aebab14d829be36994358a9c99 otherFunctions #> 22: 467bc9aebab14d829be36994358a9c99 preDigest #> 23: 467bc9aebab14d829be36994358a9c99 preDigest #> artifact tagKey #> tagValue createdDate #> 1: rda 2018-11-09 08:47:22 #> 2: 467bc9aebab14d829be36994358a9c99 2018-11-09 08:47:22 #> 3: numeric 2018-11-09 08:47:22 #> 4: 2018-11-09 08:47:22 2018-11-09 08:47:22 #> 5: f55d44974d91fbf61b6cb524983b1ebc 2018-11-09 08:47:22 #> 6: a 2018-11-09 08:47:22 #> 7: rnorm 2018-11-09 08:47:22 #> 8: 1024 2018-11-09 08:47:22 #> 9: 2018-11-09 08:47:22 2018-11-09 08:47:22 #> 10: withCallingHandlers 2018-11-09 08:47:22 #> 11: saveRDS 2018-11-09 08:47:22 #> 12: do.call 2018-11-09 08:47:22 #> 13: build_site_local 2018-11-09 08:47:22 #> 14: build_reference 2018-11-09 08:47:22 #> 15: data_reference_topic 2018-11-09 08:47:22 #> 16: as_data 2018-11-09 08:47:22 #> 17: as_data.tag_examples 2018-11-09 08:47:22 #> 18: timing_fn 2018-11-09 08:47:22 #> 19: handle 2018-11-09 08:47:22 #> 20: try 2018-11-09 08:47:22 #> 21: withVisible 2018-11-09 08:47:22 #> 22: n:c1de94a5a8d2a5813e07152fb7ea2038 2018-11-09 08:47:22 #> 23: .FUN:a979d0700a6ef8c7c18736096ff1d522 2018-11-09 08:47:22 #> tagValue createdDate
# 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