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 = character(), after, before, ...)

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

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

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

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

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

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): 21.1 Kb
#> Selected objects (not including Rasters): 727 bytes
#> artifact tagKey #> 1: 70bbd5c0490502e18570e82094212c4f format #> 2: 70bbd5c0490502e18570e82094212c4f name #> 3: 70bbd5c0490502e18570e82094212c4f class #> 4: 70bbd5c0490502e18570e82094212c4f date #> 5: 70bbd5c0490502e18570e82094212c4f cacheId #> 6: 70bbd5c0490502e18570e82094212c4f objectName #> 7: 70bbd5c0490502e18570e82094212c4f function #> 8: 70bbd5c0490502e18570e82094212c4f object.size #> 9: 70bbd5c0490502e18570e82094212c4f accessed #> 10: 70bbd5c0490502e18570e82094212c4f otherFunctions #> 11: 70bbd5c0490502e18570e82094212c4f otherFunctions #> 12: 70bbd5c0490502e18570e82094212c4f otherFunctions #> 13: 70bbd5c0490502e18570e82094212c4f otherFunctions #> 14: 70bbd5c0490502e18570e82094212c4f otherFunctions #> 15: 70bbd5c0490502e18570e82094212c4f otherFunctions #> 16: 70bbd5c0490502e18570e82094212c4f otherFunctions #> 17: 70bbd5c0490502e18570e82094212c4f preDigest #> 18: 70bbd5c0490502e18570e82094212c4f preDigest #> 19: e25845395864909089203fb2ba88764b format #> 20: e25845395864909089203fb2ba88764b name #> 21: e25845395864909089203fb2ba88764b class #> 22: e25845395864909089203fb2ba88764b date #> 23: e25845395864909089203fb2ba88764b cacheId #> 24: e25845395864909089203fb2ba88764b objectName #> 25: e25845395864909089203fb2ba88764b function #> 26: e25845395864909089203fb2ba88764b object.size #> 27: e25845395864909089203fb2ba88764b accessed #> 28: e25845395864909089203fb2ba88764b otherFunctions #> 29: e25845395864909089203fb2ba88764b otherFunctions #> 30: e25845395864909089203fb2ba88764b otherFunctions #> 31: e25845395864909089203fb2ba88764b otherFunctions #> 32: e25845395864909089203fb2ba88764b otherFunctions #> 33: e25845395864909089203fb2ba88764b otherFunctions #> 34: e25845395864909089203fb2ba88764b otherFunctions #> 35: e25845395864909089203fb2ba88764b preDigest #> 36: e25845395864909089203fb2ba88764b preDigest #> 37: ff6d60c7400fd53d42710b954770abb2 format #> 38: ff6d60c7400fd53d42710b954770abb2 name #> 39: ff6d60c7400fd53d42710b954770abb2 class #> 40: ff6d60c7400fd53d42710b954770abb2 date #> 41: ff6d60c7400fd53d42710b954770abb2 cacheId #> 42: ff6d60c7400fd53d42710b954770abb2 objectName #> 43: ff6d60c7400fd53d42710b954770abb2 function #> 44: ff6d60c7400fd53d42710b954770abb2 object.size #> 45: ff6d60c7400fd53d42710b954770abb2 accessed #> 46: ff6d60c7400fd53d42710b954770abb2 otherFunctions #> 47: ff6d60c7400fd53d42710b954770abb2 otherFunctions #> 48: ff6d60c7400fd53d42710b954770abb2 otherFunctions #> 49: ff6d60c7400fd53d42710b954770abb2 otherFunctions #> 50: ff6d60c7400fd53d42710b954770abb2 otherFunctions #> 51: ff6d60c7400fd53d42710b954770abb2 otherFunctions #> 52: ff6d60c7400fd53d42710b954770abb2 otherFunctions #> 53: ff6d60c7400fd53d42710b954770abb2 preDigest #> 54: ff6d60c7400fd53d42710b954770abb2 preDigest #> artifact tagKey #> tagValue createdDate #> 1: rda 2018-07-13 21:42:36 #> 2: Cache 2018-07-13 21:42:36 #> 3: numeric 2018-07-13 21:42:36 #> 4: 2018-07-13 21:42:36 2018-07-13 21:42:36 #> 5: b419232b60eb6eedb59532cf0b592010 2018-07-13 21:42:36 #> 6: b 2018-07-13 21:42:36 #> 7: runif 2018-07-13 21:42:36 #> 8: 976 2018-07-13 21:42:36 #> 9: 2018-07-13 21:42:36 2018-07-13 21:42:36 #> 10: withCallingHandlers 2018-07-13 21:42:36 #> 11: saveRDS 2018-07-13 21:42:36 #> 12: do.call 2018-07-13 21:42:36 #> 13: build_site_local 2018-07-13 21:42:36 #> 14: build_reference 2018-07-13 21:42:36 #> 15: data_reference_topic 2018-07-13 21:42:36 #> 16: try 2018-07-13 21:42:36 #> 17: n:9d7bd914b9878238bccd5686a5a41903 2018-07-13 21:42:36 #> 18: .FUN:d2631d24c3b38b89c7bdd4ab7faaaac3 2018-07-13 21:42:36 #> 19: rda 2018-07-13 21:42:36 #> 20: Cache 2018-07-13 21:42:36 #> 21: numeric 2018-07-13 21:42:36 #> 22: 2018-07-13 21:42:36 2018-07-13 21:42:36 #> 23: 85874f26b2e0c1ef689a7d379d275ebf 2018-07-13 21:42:36 #> 24: a 2018-07-13 21:42:36 #> 25: rnorm 2018-07-13 21:42:36 #> 26: 688 2018-07-13 21:42:36 #> 27: 2018-07-13 21:42:36 2018-07-13 21:42:36 #> 28: withCallingHandlers 2018-07-13 21:42:36 #> 29: saveRDS 2018-07-13 21:42:36 #> 30: do.call 2018-07-13 21:42:36 #> 31: build_site_local 2018-07-13 21:42:36 #> 32: build_reference 2018-07-13 21:42:36 #> 33: data_reference_topic 2018-07-13 21:42:36 #> 34: try 2018-07-13 21:42:36 #> 35: n:969a49ec15bcd4323ff31538af321264 2018-07-13 21:42:36 #> 36: .FUN:7e9a928f110f80b3612e71883a6ec1f4 2018-07-13 21:42:36 #> 37: rda 2018-07-13 21:42:36 #> 38: Cache 2018-07-13 21:42:36 #> 39: numeric 2018-07-13 21:42:36 #> 40: 2018-07-13 21:42:36 2018-07-13 21:42:36 #> 41: e37bb635c97bc2eeecab63816b881bbc 2018-07-13 21:42:36 #> 42: b 2018-07-13 21:42:36 #> 43: runif 2018-07-13 21:42:36 #> 44: 688 2018-07-13 21:42:36 #> 45: 2018-07-13 21:42:36 2018-07-13 21:42:36 #> 46: withCallingHandlers 2018-07-13 21:42:36 #> 47: saveRDS 2018-07-13 21:42:36 #> 48: do.call 2018-07-13 21:42:36 #> 49: build_site_local 2018-07-13 21:42:36 #> 50: build_reference 2018-07-13 21:42:36 #> 51: data_reference_topic 2018-07-13 21:42:36 #> 52: try 2018-07-13 21:42:36 #> 53: n:969a49ec15bcd4323ff31538af321264 2018-07-13 21:42:36 #> 54: .FUN:d2631d24c3b38b89c7bdd4ab7faaaac3 2018-07-13 21:42:36 #> tagValue createdDate
showCache(tmpDir, userTags = c("^a$")) # regular expression ... "a" exactly
#> Cache size:
#> Total (including Rasters): 21.1 Kb
#> Selected objects (not including Rasters): 172 bytes
#> artifact tagKey #> 1: e25845395864909089203fb2ba88764b format #> 2: e25845395864909089203fb2ba88764b name #> 3: e25845395864909089203fb2ba88764b class #> 4: e25845395864909089203fb2ba88764b date #> 5: e25845395864909089203fb2ba88764b cacheId #> 6: e25845395864909089203fb2ba88764b objectName #> 7: e25845395864909089203fb2ba88764b function #> 8: e25845395864909089203fb2ba88764b object.size #> 9: e25845395864909089203fb2ba88764b accessed #> 10: e25845395864909089203fb2ba88764b otherFunctions #> 11: e25845395864909089203fb2ba88764b otherFunctions #> 12: e25845395864909089203fb2ba88764b otherFunctions #> 13: e25845395864909089203fb2ba88764b otherFunctions #> 14: e25845395864909089203fb2ba88764b otherFunctions #> 15: e25845395864909089203fb2ba88764b otherFunctions #> 16: e25845395864909089203fb2ba88764b otherFunctions #> 17: e25845395864909089203fb2ba88764b preDigest #> 18: e25845395864909089203fb2ba88764b preDigest #> tagValue createdDate #> 1: rda 2018-07-13 21:42:36 #> 2: Cache 2018-07-13 21:42:36 #> 3: numeric 2018-07-13 21:42:36 #> 4: 2018-07-13 21:42:36 2018-07-13 21:42:36 #> 5: 85874f26b2e0c1ef689a7d379d275ebf 2018-07-13 21:42:36 #> 6: a 2018-07-13 21:42:36 #> 7: rnorm 2018-07-13 21:42:36 #> 8: 688 2018-07-13 21:42:36 #> 9: 2018-07-13 21:42:36 2018-07-13 21:42:36 #> 10: withCallingHandlers 2018-07-13 21:42:36 #> 11: saveRDS 2018-07-13 21:42:36 #> 12: do.call 2018-07-13 21:42:36 #> 13: build_site_local 2018-07-13 21:42:36 #> 14: build_reference 2018-07-13 21:42:36 #> 15: data_reference_topic 2018-07-13 21:42:36 #> 16: try 2018-07-13 21:42:36 #> 17: n:969a49ec15bcd4323ff31538af321264 2018-07-13 21:42:36 #> 18: .FUN:7e9a928f110f80b3612e71883a6ec1f4 2018-07-13 21:42:36
# 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): 21.1 Kb
#> Selected objects (not including Rasters): 555 bytes
toRemove <- cache1[tagKey=="object.size"][as.numeric(tagValue) > 700]$artifact clearCache(tmpDir, userTags = toRemove)
#> Cache size:
#> Total (including Rasters): 21.1 Kb
#> Selected objects (not including Rasters): 391 bytes
cacheAfter <- showCache(tmpDir, userTags = c("runif")) # Only the small one is left
#> Cache size:
#> Total (including Rasters): 20.8 Kb
#> Selected objects (not including Rasters): 164 bytes