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, ...)
| 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 | 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 |
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.
clearCacheremove items from the cache based on their
userTag or times values.
keepCacheremove all cached items except those based on
certain userTags or times values.
showCachedisplay the contents of the cache.
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.
mergeCache, splitTagsLocal. Many more examples
in Cache
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#>#>#># 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"))#>#>#>#> 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 createdDateshowCache(tmpDir, userTags = c("^a$")) # regular expression ... "a" exactly#>#>#>#> 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#>#>#>toRemove <- cache1[tagKey=="object.size"][as.numeric(tagValue) > 700]$artifact clearCache(tmpDir, userTags = toRemove)#>#>#>cacheAfter <- showCache(tmpDir, userTags = c("runif")) # Only the small one is left#>#>#>