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.

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.

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.

Value

Will clear all (or that match userTags, or between after or before) objects from the repository located at cachePath of the sim object, if sim is provided, or located in cacheRepo. Also returns a data.table invisibly 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): 724 bytes
#> artifact tagKey #> 1: 9b59839e70b2f18c564b263895b536d8 format #> 2: 9b59839e70b2f18c564b263895b536d8 name #> 3: 9b59839e70b2f18c564b263895b536d8 class #> 4: 9b59839e70b2f18c564b263895b536d8 date #> 5: 9b59839e70b2f18c564b263895b536d8 cacheId #> 6: 9b59839e70b2f18c564b263895b536d8 objectName #> 7: 9b59839e70b2f18c564b263895b536d8 function #> 8: 9b59839e70b2f18c564b263895b536d8 object.size #> 9: 9b59839e70b2f18c564b263895b536d8 accessed #> 10: 9b59839e70b2f18c564b263895b536d8 otherFunctions #> 11: 9b59839e70b2f18c564b263895b536d8 otherFunctions #> 12: 9b59839e70b2f18c564b263895b536d8 otherFunctions #> 13: 9b59839e70b2f18c564b263895b536d8 otherFunctions #> 14: 9b59839e70b2f18c564b263895b536d8 otherFunctions #> 15: 9b59839e70b2f18c564b263895b536d8 otherFunctions #> 16: 9b59839e70b2f18c564b263895b536d8 otherFunctions #> 17: 9b59839e70b2f18c564b263895b536d8 preDigest #> 18: 9b59839e70b2f18c564b263895b536d8 preDigest #> 19: af8f6100c05519943ab61f41464632e6 format #> 20: af8f6100c05519943ab61f41464632e6 name #> 21: af8f6100c05519943ab61f41464632e6 class #> 22: af8f6100c05519943ab61f41464632e6 date #> 23: af8f6100c05519943ab61f41464632e6 cacheId #> 24: af8f6100c05519943ab61f41464632e6 objectName #> 25: af8f6100c05519943ab61f41464632e6 function #> 26: af8f6100c05519943ab61f41464632e6 object.size #> 27: af8f6100c05519943ab61f41464632e6 accessed #> 28: af8f6100c05519943ab61f41464632e6 otherFunctions #> 29: af8f6100c05519943ab61f41464632e6 otherFunctions #> 30: af8f6100c05519943ab61f41464632e6 otherFunctions #> 31: af8f6100c05519943ab61f41464632e6 otherFunctions #> 32: af8f6100c05519943ab61f41464632e6 otherFunctions #> 33: af8f6100c05519943ab61f41464632e6 otherFunctions #> 34: af8f6100c05519943ab61f41464632e6 otherFunctions #> 35: af8f6100c05519943ab61f41464632e6 preDigest #> 36: af8f6100c05519943ab61f41464632e6 preDigest #> 37: fd52ce513075ca5b8c99da74d4089f41 format #> 38: fd52ce513075ca5b8c99da74d4089f41 name #> 39: fd52ce513075ca5b8c99da74d4089f41 class #> 40: fd52ce513075ca5b8c99da74d4089f41 date #> 41: fd52ce513075ca5b8c99da74d4089f41 cacheId #> 42: fd52ce513075ca5b8c99da74d4089f41 objectName #> 43: fd52ce513075ca5b8c99da74d4089f41 function #> 44: fd52ce513075ca5b8c99da74d4089f41 object.size #> 45: fd52ce513075ca5b8c99da74d4089f41 accessed #> 46: fd52ce513075ca5b8c99da74d4089f41 otherFunctions #> 47: fd52ce513075ca5b8c99da74d4089f41 otherFunctions #> 48: fd52ce513075ca5b8c99da74d4089f41 otherFunctions #> 49: fd52ce513075ca5b8c99da74d4089f41 otherFunctions #> 50: fd52ce513075ca5b8c99da74d4089f41 otherFunctions #> 51: fd52ce513075ca5b8c99da74d4089f41 otherFunctions #> 52: fd52ce513075ca5b8c99da74d4089f41 otherFunctions #> 53: fd52ce513075ca5b8c99da74d4089f41 preDigest #> 54: fd52ce513075ca5b8c99da74d4089f41 preDigest #> artifact tagKey #> tagValue createdDate #> 1: rda 2018-06-15 10:20:38 #> 2: Cache 2018-06-15 10:20:38 #> 3: numeric 2018-06-15 10:20:38 #> 4: 2018-06-15 10:20:38 2018-06-15 10:20:38 #> 5: e37bb635c97bc2eeecab63816b881bbc 2018-06-15 10:20:38 #> 6: b 2018-06-15 10:20:38 #> 7: runif 2018-06-15 10:20:38 #> 8: 688 2018-06-15 10:20:38 #> 9: 2018-06-15 10:20:38 2018-06-15 10:20:38 #> 10: withCallingHandlers 2018-06-15 10:20:38 #> 11: saveRDS 2018-06-15 10:20:38 #> 12: do.call 2018-06-15 10:20:38 #> 13: build_site_local 2018-06-15 10:20:38 #> 14: build_reference 2018-06-15 10:20:38 #> 15: data_reference_topic 2018-06-15 10:20:38 #> 16: try 2018-06-15 10:20:38 #> 17: n:969a49ec15bcd4323ff31538af321264 2018-06-15 10:20:38 #> 18: .FUN:d2631d24c3b38b89c7bdd4ab7faaaac3 2018-06-15 10:20:38 #> 19: rda 2018-06-15 10:20:38 #> 20: Cache 2018-06-15 10:20:38 #> 21: numeric 2018-06-15 10:20:38 #> 22: 2018-06-15 10:20:38 2018-06-15 10:20:38 #> 23: b419232b60eb6eedb59532cf0b592010 2018-06-15 10:20:38 #> 24: b 2018-06-15 10:20:38 #> 25: runif 2018-06-15 10:20:38 #> 26: 976 2018-06-15 10:20:38 #> 27: 2018-06-15 10:20:38 2018-06-15 10:20:38 #> 28: withCallingHandlers 2018-06-15 10:20:38 #> 29: saveRDS 2018-06-15 10:20:38 #> 30: do.call 2018-06-15 10:20:38 #> 31: build_site_local 2018-06-15 10:20:38 #> 32: build_reference 2018-06-15 10:20:38 #> 33: data_reference_topic 2018-06-15 10:20:38 #> 34: try 2018-06-15 10:20:38 #> 35: n:9d7bd914b9878238bccd5686a5a41903 2018-06-15 10:20:38 #> 36: .FUN:d2631d24c3b38b89c7bdd4ab7faaaac3 2018-06-15 10:20:38 #> 37: rda 2018-06-15 10:20:38 #> 38: Cache 2018-06-15 10:20:38 #> 39: numeric 2018-06-15 10:20:38 #> 40: 2018-06-15 10:20:38 2018-06-15 10:20:38 #> 41: 85874f26b2e0c1ef689a7d379d275ebf 2018-06-15 10:20:38 #> 42: a 2018-06-15 10:20:38 #> 43: rnorm 2018-06-15 10:20:38 #> 44: 688 2018-06-15 10:20:38 #> 45: 2018-06-15 10:20:38 2018-06-15 10:20:38 #> 46: withCallingHandlers 2018-06-15 10:20:38 #> 47: saveRDS 2018-06-15 10:20:38 #> 48: do.call 2018-06-15 10:20:38 #> 49: build_site_local 2018-06-15 10:20:38 #> 50: build_reference 2018-06-15 10:20:38 #> 51: data_reference_topic 2018-06-15 10:20:38 #> 52: try 2018-06-15 10:20:38 #> 53: n:969a49ec15bcd4323ff31538af321264 2018-06-15 10:20:38 #> 54: .FUN:7e9a928f110f80b3612e71883a6ec1f4 2018-06-15 10:20:38 #> tagValue createdDate
showCache(tmpDir, userTags = c("^a$")) # regular expression ... "a" exactly
#> Cache size:
#> Total (including Rasters): 21.1 Kb
#> Selected objects (not including Rasters): 171 bytes
#> artifact tagKey #> 1: fd52ce513075ca5b8c99da74d4089f41 format #> 2: fd52ce513075ca5b8c99da74d4089f41 name #> 3: fd52ce513075ca5b8c99da74d4089f41 class #> 4: fd52ce513075ca5b8c99da74d4089f41 date #> 5: fd52ce513075ca5b8c99da74d4089f41 cacheId #> 6: fd52ce513075ca5b8c99da74d4089f41 objectName #> 7: fd52ce513075ca5b8c99da74d4089f41 function #> 8: fd52ce513075ca5b8c99da74d4089f41 object.size #> 9: fd52ce513075ca5b8c99da74d4089f41 accessed #> 10: fd52ce513075ca5b8c99da74d4089f41 otherFunctions #> 11: fd52ce513075ca5b8c99da74d4089f41 otherFunctions #> 12: fd52ce513075ca5b8c99da74d4089f41 otherFunctions #> 13: fd52ce513075ca5b8c99da74d4089f41 otherFunctions #> 14: fd52ce513075ca5b8c99da74d4089f41 otherFunctions #> 15: fd52ce513075ca5b8c99da74d4089f41 otherFunctions #> 16: fd52ce513075ca5b8c99da74d4089f41 otherFunctions #> 17: fd52ce513075ca5b8c99da74d4089f41 preDigest #> 18: fd52ce513075ca5b8c99da74d4089f41 preDigest #> tagValue createdDate #> 1: rda 2018-06-15 10:20:38 #> 2: Cache 2018-06-15 10:20:38 #> 3: numeric 2018-06-15 10:20:38 #> 4: 2018-06-15 10:20:38 2018-06-15 10:20:38 #> 5: 85874f26b2e0c1ef689a7d379d275ebf 2018-06-15 10:20:38 #> 6: a 2018-06-15 10:20:38 #> 7: rnorm 2018-06-15 10:20:38 #> 8: 688 2018-06-15 10:20:38 #> 9: 2018-06-15 10:20:38 2018-06-15 10:20:38 #> 10: withCallingHandlers 2018-06-15 10:20:38 #> 11: saveRDS 2018-06-15 10:20:38 #> 12: do.call 2018-06-15 10:20:38 #> 13: build_site_local 2018-06-15 10:20:38 #> 14: build_reference 2018-06-15 10:20:38 #> 15: data_reference_topic 2018-06-15 10:20:38 #> 16: try 2018-06-15 10:20:38 #> 17: n:969a49ec15bcd4323ff31538af321264 2018-06-15 10:20:38 #> 18: .FUN:7e9a928f110f80b3612e71883a6ec1f4 2018-06-15 10:20:38
# 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): 553 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): 390 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): 163 bytes