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 expresssion, 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.

See also

splitTagsLocal.

Examples

library(raster) tmpDir <- file.path(tempdir(), "reproducible_examples", "Cache") ## Example 1: basic cache use ranNumsA <- Cache(rnorm, 4, cacheRepo = tmpDir, userTags = "objectName:a") ranNumsB <- Cache(runif, 4, cacheRepo = tmpDir, userTags = "objectName:b") showCache(tmpDir, userTags = c("objectName"))
#> artifact tagKey #> 1: 39057df8e1afbda2c2c398aacb9cd941 format #> 2: 39057df8e1afbda2c2c398aacb9cd941 name #> 3: 39057df8e1afbda2c2c398aacb9cd941 class #> 4: 39057df8e1afbda2c2c398aacb9cd941 date #> 5: 39057df8e1afbda2c2c398aacb9cd941 objectName #> 6: 39057df8e1afbda2c2c398aacb9cd941 function #> 7: 39057df8e1afbda2c2c398aacb9cd941 object.size #> 8: 39057df8e1afbda2c2c398aacb9cd941 accessed #> 9: 39057df8e1afbda2c2c398aacb9cd941 cacheId #> 10: a1ddbaaf900ba6ae7c987dbcaebe4c02 format #> 11: a1ddbaaf900ba6ae7c987dbcaebe4c02 name #> 12: a1ddbaaf900ba6ae7c987dbcaebe4c02 class #> 13: a1ddbaaf900ba6ae7c987dbcaebe4c02 date #> 14: a1ddbaaf900ba6ae7c987dbcaebe4c02 objectName #> 15: a1ddbaaf900ba6ae7c987dbcaebe4c02 function #> 16: a1ddbaaf900ba6ae7c987dbcaebe4c02 object.size #> 17: a1ddbaaf900ba6ae7c987dbcaebe4c02 accessed #> 18: a1ddbaaf900ba6ae7c987dbcaebe4c02 cacheId #> tagValue createdDate #> 1: rda 2017-09-05 16:33:35 #> 2: Cache 2017-09-05 16:33:35 #> 3: numeric 2017-09-05 16:33:35 #> 4: 2017-09-05 16:33:35 2017-09-05 16:33:35 #> 5: a 2017-09-05 16:33:35 #> 6: rnorm 2017-09-05 16:33:35 #> 7: 528 2017-09-05 16:33:35 #> 8: 2017-09-05 16:33:35 2017-09-05 16:33:35 #> 9: 6c02ed3587ff36e0f232dc296099540b 2017-09-05 16:33:35 #> 10: rda 2017-09-05 16:33:35 #> 11: Cache 2017-09-05 16:33:35 #> 12: numeric 2017-09-05 16:33:35 #> 13: 2017-09-05 16:33:35 2017-09-05 16:33:35 #> 14: b 2017-09-05 16:33:35 #> 15: runif 2017-09-05 16:33:35 #> 16: 528 2017-09-05 16:33:35 #> 17: 2017-09-05 16:33:35 2017-09-05 16:33:35 #> 18: 9dd2494a488858266cd45d230f45a144 2017-09-05 16:33:35
showCache(tmpDir, userTags = c("^a$")) # regular expression ... "a" exactly
#> artifact tagKey #> 1: 39057df8e1afbda2c2c398aacb9cd941 format #> 2: 39057df8e1afbda2c2c398aacb9cd941 name #> 3: 39057df8e1afbda2c2c398aacb9cd941 class #> 4: 39057df8e1afbda2c2c398aacb9cd941 date #> 5: 39057df8e1afbda2c2c398aacb9cd941 objectName #> 6: 39057df8e1afbda2c2c398aacb9cd941 function #> 7: 39057df8e1afbda2c2c398aacb9cd941 object.size #> 8: 39057df8e1afbda2c2c398aacb9cd941 accessed #> 9: 39057df8e1afbda2c2c398aacb9cd941 cacheId #> tagValue createdDate #> 1: rda 2017-09-05 16:33:35 #> 2: Cache 2017-09-05 16:33:35 #> 3: numeric 2017-09-05 16:33:35 #> 4: 2017-09-05 16:33:35 2017-09-05 16:33:35 #> 5: a 2017-09-05 16:33:35 #> 6: rnorm 2017-09-05 16:33:35 #> 7: 528 2017-09-05 16:33:35 #> 8: 2017-09-05 16:33:35 2017-09-05 16:33:35 #> 9: 6c02ed3587ff36e0f232dc296099540b 2017-09-05 16:33:35
showCache(tmpDir, userTags = c("runif")) # show only cached objects made during runif call
#> artifact tagKey #> 1: a1ddbaaf900ba6ae7c987dbcaebe4c02 format #> 2: a1ddbaaf900ba6ae7c987dbcaebe4c02 name #> 3: a1ddbaaf900ba6ae7c987dbcaebe4c02 class #> 4: a1ddbaaf900ba6ae7c987dbcaebe4c02 date #> 5: a1ddbaaf900ba6ae7c987dbcaebe4c02 objectName #> 6: a1ddbaaf900ba6ae7c987dbcaebe4c02 function #> 7: a1ddbaaf900ba6ae7c987dbcaebe4c02 object.size #> 8: a1ddbaaf900ba6ae7c987dbcaebe4c02 accessed #> 9: a1ddbaaf900ba6ae7c987dbcaebe4c02 cacheId #> tagValue createdDate #> 1: rda 2017-09-05 16:33:35 #> 2: Cache 2017-09-05 16:33:35 #> 3: numeric 2017-09-05 16:33:35 #> 4: 2017-09-05 16:33:35 2017-09-05 16:33:35 #> 5: b 2017-09-05 16:33:35 #> 6: runif 2017-09-05 16:33:35 #> 7: 528 2017-09-05 16:33:35 #> 8: 2017-09-05 16:33:35 2017-09-05 16:33:35 #> 9: 9dd2494a488858266cd45d230f45a144 2017-09-05 16:33:35
clearCache(tmpDir, userTags = c("runif")) # remove only cached objects made during runif call showCache(tmpDir) # only those made during rnorm call
#> artifact tagKey #> 1: 39057df8e1afbda2c2c398aacb9cd941 format #> 2: 39057df8e1afbda2c2c398aacb9cd941 name #> 3: 39057df8e1afbda2c2c398aacb9cd941 class #> 4: 39057df8e1afbda2c2c398aacb9cd941 date #> 5: 39057df8e1afbda2c2c398aacb9cd941 objectName #> 6: 39057df8e1afbda2c2c398aacb9cd941 function #> 7: 39057df8e1afbda2c2c398aacb9cd941 object.size #> 8: 39057df8e1afbda2c2c398aacb9cd941 accessed #> 9: 39057df8e1afbda2c2c398aacb9cd941 cacheId #> tagValue createdDate #> 1: rda 2017-09-05 16:33:35 #> 2: Cache 2017-09-05 16:33:35 #> 3: numeric 2017-09-05 16:33:35 #> 4: 2017-09-05 16:33:35 2017-09-05 16:33:35 #> 5: a 2017-09-05 16:33:35 #> 6: rnorm 2017-09-05 16:33:35 #> 7: 528 2017-09-05 16:33:35 #> 8: 2017-09-05 16:33:35 2017-09-05 16:33:35 #> 9: 6c02ed3587ff36e0f232dc296099540b 2017-09-05 16:33:35
clearCache(tmpDir) ## Example 2: using the "accessed" tag ranNumsA <- Cache(rnorm, 4, cacheRepo = tmpDir, userTags = "objectName:a") ranNumsB <- Cache(runif, 4, cacheRepo = tmpDir, userTags = "objectName:b") # access it again, but "later" Sys.sleep(1) ranNumsA <- Cache(rnorm, 4, cacheRepo = tmpDir, userTags = "objectName:a")
#> loading cached result from previous rnorm call.
wholeCache <- showCache(tmpDir) # keep only items accessed "recently" (i.e., only objectName:a) onlyRecentlyAccessed <- showCache(tmpDir, userTags = max(wholeCache[tagKey == "accessed"]$tagValue)) # inverse join with 2 data.tables ... using: a[!b] # i.e., return all of wholeCache that was not recently accessed toRemove <- unique(wholeCache[!onlyRecentlyAccessed], by = "artifact")$artifact clearCache(tmpDir, toRemove) # remove ones not recently accessed showCache(tmpDir) # still has more recently accessed
#> artifact tagKey #> 1: bb2f7c8a3de4346bb8d6e00161130064 format #> 2: bb2f7c8a3de4346bb8d6e00161130064 name #> 3: bb2f7c8a3de4346bb8d6e00161130064 class #> 4: bb2f7c8a3de4346bb8d6e00161130064 date #> 5: bb2f7c8a3de4346bb8d6e00161130064 objectName #> 6: bb2f7c8a3de4346bb8d6e00161130064 function #> 7: bb2f7c8a3de4346bb8d6e00161130064 object.size #> 8: bb2f7c8a3de4346bb8d6e00161130064 accessed #> 9: bb2f7c8a3de4346bb8d6e00161130064 cacheId #> 10: bb2f7c8a3de4346bb8d6e00161130064 accessed #> tagValue createdDate #> 1: rda 2017-09-05 16:33:35 #> 2: Cache 2017-09-05 16:33:35 #> 3: numeric 2017-09-05 16:33:35 #> 4: 2017-09-05 16:33:35 2017-09-05 16:33:35 #> 5: a 2017-09-05 16:33:35 #> 6: rnorm 2017-09-05 16:33:35 #> 7: 528 2017-09-05 16:33:35 #> 8: 2017-09-05 16:33:35 2017-09-05 16:33:35 #> 9: 6c02ed3587ff36e0f232dc296099540b 2017-09-05 16:33:35 #> 10: 2017-09-05 16:33:36 2017-09-05 16:33:36
clearCache(tmpDir) ## Example 3: using keepCache ranNumsA <- Cache(rnorm, 4, cacheRepo = tmpDir, userTags = "objectName:a") ranNumsB <- Cache(runif, 4, cacheRepo = tmpDir, userTags = "objectName:b") # keep only those cached items from the last 24 hours oneDay <- 60 * 60 * 24 keepCache(tmpDir, after = Sys.time() - oneDay)
#> artifact tagKey #> 1: 1875a835f4f37b93a1e4c7fc731b4070 format #> 2: 1875a835f4f37b93a1e4c7fc731b4070 name #> 3: 1875a835f4f37b93a1e4c7fc731b4070 class #> 4: 1875a835f4f37b93a1e4c7fc731b4070 date #> 5: 1875a835f4f37b93a1e4c7fc731b4070 objectName #> 6: 1875a835f4f37b93a1e4c7fc731b4070 function #> 7: 1875a835f4f37b93a1e4c7fc731b4070 object.size #> 8: 1875a835f4f37b93a1e4c7fc731b4070 accessed #> 9: 1875a835f4f37b93a1e4c7fc731b4070 cacheId #> 10: a316ba75056133bd6bd3da88fc3afd6f format #> 11: a316ba75056133bd6bd3da88fc3afd6f name #> 12: a316ba75056133bd6bd3da88fc3afd6f class #> 13: a316ba75056133bd6bd3da88fc3afd6f date #> 14: a316ba75056133bd6bd3da88fc3afd6f objectName #> 15: a316ba75056133bd6bd3da88fc3afd6f function #> 16: a316ba75056133bd6bd3da88fc3afd6f object.size #> 17: a316ba75056133bd6bd3da88fc3afd6f accessed #> 18: a316ba75056133bd6bd3da88fc3afd6f cacheId #> tagValue createdDate #> 1: rda 2017-09-05 16:33:36 #> 2: Cache 2017-09-05 16:33:36 #> 3: numeric 2017-09-05 16:33:36 #> 4: 2017-09-05 16:33:36 2017-09-05 16:33:36 #> 5: a 2017-09-05 16:33:36 #> 6: rnorm 2017-09-05 16:33:36 #> 7: 528 2017-09-05 16:33:36 #> 8: 2017-09-05 16:33:36 2017-09-05 16:33:36 #> 9: 6c02ed3587ff36e0f232dc296099540b 2017-09-05 16:33:36 #> 10: rda 2017-09-05 16:33:36 #> 11: Cache 2017-09-05 16:33:36 #> 12: numeric 2017-09-05 16:33:36 #> 13: 2017-09-05 16:33:36 2017-09-05 16:33:36 #> 14: b 2017-09-05 16:33:36 #> 15: runif 2017-09-05 16:33:36 #> 16: 528 2017-09-05 16:33:36 #> 17: 2017-09-05 16:33:36 2017-09-05 16:33:36 #> 18: 9dd2494a488858266cd45d230f45a144 2017-09-05 16:33:36
# Keep all Cache items created with an rnorm() call keepCache(tmpDir, userTags = "rnorm")
#> artifact tagKey #> 1: 1875a835f4f37b93a1e4c7fc731b4070 format #> 2: 1875a835f4f37b93a1e4c7fc731b4070 name #> 3: 1875a835f4f37b93a1e4c7fc731b4070 class #> 4: 1875a835f4f37b93a1e4c7fc731b4070 date #> 5: 1875a835f4f37b93a1e4c7fc731b4070 objectName #> 6: 1875a835f4f37b93a1e4c7fc731b4070 function #> 7: 1875a835f4f37b93a1e4c7fc731b4070 object.size #> 8: 1875a835f4f37b93a1e4c7fc731b4070 accessed #> 9: 1875a835f4f37b93a1e4c7fc731b4070 cacheId #> tagValue createdDate #> 1: rda 2017-09-05 16:33:36 #> 2: Cache 2017-09-05 16:33:36 #> 3: numeric 2017-09-05 16:33:36 #> 4: 2017-09-05 16:33:36 2017-09-05 16:33:36 #> 5: a 2017-09-05 16:33:36 #> 6: rnorm 2017-09-05 16:33:36 #> 7: 528 2017-09-05 16:33:36 #> 8: 2017-09-05 16:33:36 2017-09-05 16:33:36 #> 9: 6c02ed3587ff36e0f232dc296099540b 2017-09-05 16:33:36
# Remove all Cache items that happened within a rnorm() call clearCache(tmpDir, userTags = "rnorm") showCache(tmpDir) ## empty
#> Empty data.table (0 rows) of 3 cols: md5hash,name,createdDate
## Example 4: searching for multiple objects in the cache # default userTags is "and" matching; for "or" matching use | ranNumsA <- Cache(runif, 4, cacheRepo = tmpDir, userTags = "objectName:a") ranNumsB <- Cache(rnorm, 4, cacheRepo = tmpDir, userTags = "objectName:b") # show all objects (runif and rnorm in this case) showCache(tmpDir)
#> artifact tagKey #> 1: 55c9629b91a3a542340f236190b896db format #> 2: 55c9629b91a3a542340f236190b896db name #> 3: 55c9629b91a3a542340f236190b896db class #> 4: 55c9629b91a3a542340f236190b896db date #> 5: 55c9629b91a3a542340f236190b896db objectName #> 6: 55c9629b91a3a542340f236190b896db function #> 7: 55c9629b91a3a542340f236190b896db object.size #> 8: 55c9629b91a3a542340f236190b896db accessed #> 9: 55c9629b91a3a542340f236190b896db cacheId #> 10: 947b8abb36621ffc87ba4a5ca20d017f format #> 11: 947b8abb36621ffc87ba4a5ca20d017f name #> 12: 947b8abb36621ffc87ba4a5ca20d017f class #> 13: 947b8abb36621ffc87ba4a5ca20d017f date #> 14: 947b8abb36621ffc87ba4a5ca20d017f objectName #> 15: 947b8abb36621ffc87ba4a5ca20d017f function #> 16: 947b8abb36621ffc87ba4a5ca20d017f object.size #> 17: 947b8abb36621ffc87ba4a5ca20d017f accessed #> 18: 947b8abb36621ffc87ba4a5ca20d017f cacheId #> tagValue createdDate #> 1: rda 2017-09-05 16:33:36 #> 2: Cache 2017-09-05 16:33:36 #> 3: numeric 2017-09-05 16:33:36 #> 4: 2017-09-05 16:33:36 2017-09-05 16:33:36 #> 5: a 2017-09-05 16:33:36 #> 6: runif 2017-09-05 16:33:36 #> 7: 528 2017-09-05 16:33:36 #> 8: 2017-09-05 16:33:36 2017-09-05 16:33:36 #> 9: 9dd2494a488858266cd45d230f45a144 2017-09-05 16:33:36 #> 10: rda 2017-09-05 16:33:36 #> 11: Cache 2017-09-05 16:33:36 #> 12: numeric 2017-09-05 16:33:36 #> 13: 2017-09-05 16:33:36 2017-09-05 16:33:36 #> 14: b 2017-09-05 16:33:36 #> 15: rnorm 2017-09-05 16:33:36 #> 16: 528 2017-09-05 16:33:36 #> 17: 2017-09-05 16:33:36 2017-09-05 16:33:36 #> 18: 6c02ed3587ff36e0f232dc296099540b 2017-09-05 16:33:36
# show objects that are both runif and rnorm # (i.e., none in this case, because objecs are either or, not both) showCache(tmpDir, userTags = c("runif", "rnorm")) ## empty
#> Empty data.table (0 rows) of 4 cols: artifact,tagKey,tagValue,createdDate
# show objects that are either runif or rnorm ("or" search) showCache(tmpDir, userTags = "runif|rnorm")
#> artifact tagKey #> 1: 55c9629b91a3a542340f236190b896db format #> 2: 55c9629b91a3a542340f236190b896db name #> 3: 55c9629b91a3a542340f236190b896db class #> 4: 55c9629b91a3a542340f236190b896db date #> 5: 55c9629b91a3a542340f236190b896db objectName #> 6: 55c9629b91a3a542340f236190b896db function #> 7: 55c9629b91a3a542340f236190b896db object.size #> 8: 55c9629b91a3a542340f236190b896db accessed #> 9: 55c9629b91a3a542340f236190b896db cacheId #> 10: 947b8abb36621ffc87ba4a5ca20d017f format #> 11: 947b8abb36621ffc87ba4a5ca20d017f name #> 12: 947b8abb36621ffc87ba4a5ca20d017f class #> 13: 947b8abb36621ffc87ba4a5ca20d017f date #> 14: 947b8abb36621ffc87ba4a5ca20d017f objectName #> 15: 947b8abb36621ffc87ba4a5ca20d017f function #> 16: 947b8abb36621ffc87ba4a5ca20d017f object.size #> 17: 947b8abb36621ffc87ba4a5ca20d017f accessed #> 18: 947b8abb36621ffc87ba4a5ca20d017f cacheId #> tagValue createdDate #> 1: rda 2017-09-05 16:33:36 #> 2: Cache 2017-09-05 16:33:36 #> 3: numeric 2017-09-05 16:33:36 #> 4: 2017-09-05 16:33:36 2017-09-05 16:33:36 #> 5: a 2017-09-05 16:33:36 #> 6: runif 2017-09-05 16:33:36 #> 7: 528 2017-09-05 16:33:36 #> 8: 2017-09-05 16:33:36 2017-09-05 16:33:36 #> 9: 9dd2494a488858266cd45d230f45a144 2017-09-05 16:33:36 #> 10: rda 2017-09-05 16:33:36 #> 11: Cache 2017-09-05 16:33:36 #> 12: numeric 2017-09-05 16:33:36 #> 13: 2017-09-05 16:33:36 2017-09-05 16:33:36 #> 14: b 2017-09-05 16:33:36 #> 15: rnorm 2017-09-05 16:33:36 #> 16: 528 2017-09-05 16:33:36 #> 17: 2017-09-05 16:33:36 2017-09-05 16:33:36 #> 18: 6c02ed3587ff36e0f232dc296099540b 2017-09-05 16:33:36
# keep only objects that are either runif or rnorm ("or" search) keepCache(tmpDir, userTags = "runif|rnorm")
#> artifact tagKey #> 1: 55c9629b91a3a542340f236190b896db format #> 2: 55c9629b91a3a542340f236190b896db name #> 3: 55c9629b91a3a542340f236190b896db class #> 4: 55c9629b91a3a542340f236190b896db date #> 5: 55c9629b91a3a542340f236190b896db objectName #> 6: 55c9629b91a3a542340f236190b896db function #> 7: 55c9629b91a3a542340f236190b896db object.size #> 8: 55c9629b91a3a542340f236190b896db accessed #> 9: 55c9629b91a3a542340f236190b896db cacheId #> 10: 947b8abb36621ffc87ba4a5ca20d017f format #> 11: 947b8abb36621ffc87ba4a5ca20d017f name #> 12: 947b8abb36621ffc87ba4a5ca20d017f class #> 13: 947b8abb36621ffc87ba4a5ca20d017f date #> 14: 947b8abb36621ffc87ba4a5ca20d017f objectName #> 15: 947b8abb36621ffc87ba4a5ca20d017f function #> 16: 947b8abb36621ffc87ba4a5ca20d017f object.size #> 17: 947b8abb36621ffc87ba4a5ca20d017f accessed #> 18: 947b8abb36621ffc87ba4a5ca20d017f cacheId #> tagValue createdDate #> 1: rda 2017-09-05 16:33:36 #> 2: Cache 2017-09-05 16:33:36 #> 3: numeric 2017-09-05 16:33:36 #> 4: 2017-09-05 16:33:36 2017-09-05 16:33:36 #> 5: a 2017-09-05 16:33:36 #> 6: runif 2017-09-05 16:33:36 #> 7: 528 2017-09-05 16:33:36 #> 8: 2017-09-05 16:33:36 2017-09-05 16:33:36 #> 9: 9dd2494a488858266cd45d230f45a144 2017-09-05 16:33:36 #> 10: rda 2017-09-05 16:33:36 #> 11: Cache 2017-09-05 16:33:36 #> 12: numeric 2017-09-05 16:33:36 #> 13: 2017-09-05 16:33:36 2017-09-05 16:33:36 #> 14: b 2017-09-05 16:33:36 #> 15: rnorm 2017-09-05 16:33:36 #> 16: 528 2017-09-05 16:33:36 #> 17: 2017-09-05 16:33:36 2017-09-05 16:33:36 #> 18: 6c02ed3587ff36e0f232dc296099540b 2017-09-05 16:33:36
clearCache(tmpDir) ## Example 5: using caching to speed up rerunning expensive computations ras <- raster(extent(0, 100, 0, 100), res = 1, vals = sample(1:5, replace = TRUE, size = 1e4), crs = "+proj=lcc +lat_1=48 +lat_2=33 +lon_0=-100 +ellps=WGS84") # A slow operation, like GIS operation notCached <- suppressWarnings( # project raster generates warnings when run non-interactively projectRaster(ras, crs = crs(ras), res = 5, cacheRepo = tmpDir) ) cached <- suppressWarnings( # project raster generates warnings when run non-interactively Cache(projectRaster, ras, crs = crs(ras), res = 5, cacheRepo = tmpDir) ) # second time is much faster reRun <- suppressWarnings( # project raster generates warnings when run non-interactively Cache(projectRaster, ras, crs = crs(ras), res = 5, cacheRepo = tmpDir) )
#> loading cached result from previous projectRaster call.
# recovered cached version is same as non-cached version all.equal(notCached, reRun) ## TRUE
#> [1] TRUE
## Example 6: working with file paths # if passing a character string, it will take 2 complete passes to before # a cached copy is used when it is a save event (read or load is different) obj <- 1:10 fname <- tempfile(fileext = ".RData") Cache(saveRDS, obj, file = fname, cacheRepo = tmpDir)
#> NULL
Cache(saveRDS, obj, file = fname, cacheRepo = tmpDir)
#> NULL
Cache(saveRDS, obj, file = fname, cacheRepo = tmpDir) # cached copy is loaded
#> loading cached result from previous saveRDS call.
#> [1] "NULL" #> attr(,"tags") #> [1] "cacheId:46db9ac49c0d1d44463ac3c5dfe3119a" #> attr(,"call") #> [1] ""
# however, using asPath(), cached version retrieved after being run once fname1 <- tempfile(fileext = ".RData") Cache(saveRDS, obj, file = asPath(fname1), cacheRepo = tmpDir)
#> NULL
Cache(saveRDS, obj, file = asPath(fname1), cacheRepo = tmpDir) # cached copy is loaded
#> loading cached result from previous saveRDS call.
#> [1] "NULL" #> attr(,"tags") #> [1] "cacheId:2499b221d634b007d7da941b7a105fed" #> attr(,"call") #> [1] ""
clearCache(tmpDir) ## cleanup unlink(c("filename.rda", "filename1.rda")) unlink(dirname(tmpDir), recursive = TRUE) library(raster) tmpDir <- file.path(tempdir(), "reproducible_examples", "Cache") ## Example 1: basic cache use ranNumsA <- Cache(rnorm, 4, cacheRepo = tmpDir, userTags = "objectName:a") ranNumsB <- Cache(runif, 4, cacheRepo = tmpDir, userTags = "objectName:b") showCache(tmpDir, userTags = c("objectName"))
#> artifact tagKey #> 1: 009e7b31957b151903fe6de1c7719e28 format #> 2: 009e7b31957b151903fe6de1c7719e28 name #> 3: 009e7b31957b151903fe6de1c7719e28 class #> 4: 009e7b31957b151903fe6de1c7719e28 date #> 5: 009e7b31957b151903fe6de1c7719e28 objectName #> 6: 009e7b31957b151903fe6de1c7719e28 function #> 7: 009e7b31957b151903fe6de1c7719e28 object.size #> 8: 009e7b31957b151903fe6de1c7719e28 accessed #> 9: 009e7b31957b151903fe6de1c7719e28 cacheId #> 10: 5a73ac00c3fdb4a0ab75c382af02ab58 format #> 11: 5a73ac00c3fdb4a0ab75c382af02ab58 name #> 12: 5a73ac00c3fdb4a0ab75c382af02ab58 class #> 13: 5a73ac00c3fdb4a0ab75c382af02ab58 date #> 14: 5a73ac00c3fdb4a0ab75c382af02ab58 objectName #> 15: 5a73ac00c3fdb4a0ab75c382af02ab58 function #> 16: 5a73ac00c3fdb4a0ab75c382af02ab58 object.size #> 17: 5a73ac00c3fdb4a0ab75c382af02ab58 accessed #> 18: 5a73ac00c3fdb4a0ab75c382af02ab58 cacheId #> tagValue createdDate #> 1: rda 2017-09-05 16:33:37 #> 2: Cache 2017-09-05 16:33:37 #> 3: numeric 2017-09-05 16:33:37 #> 4: 2017-09-05 16:33:37 2017-09-05 16:33:37 #> 5: a 2017-09-05 16:33:37 #> 6: rnorm 2017-09-05 16:33:37 #> 7: 528 2017-09-05 16:33:37 #> 8: 2017-09-05 16:33:37 2017-09-05 16:33:37 #> 9: 6c02ed3587ff36e0f232dc296099540b 2017-09-05 16:33:37 #> 10: rda 2017-09-05 16:33:37 #> 11: Cache 2017-09-05 16:33:37 #> 12: numeric 2017-09-05 16:33:37 #> 13: 2017-09-05 16:33:37 2017-09-05 16:33:37 #> 14: b 2017-09-05 16:33:37 #> 15: runif 2017-09-05 16:33:37 #> 16: 528 2017-09-05 16:33:37 #> 17: 2017-09-05 16:33:37 2017-09-05 16:33:37 #> 18: 9dd2494a488858266cd45d230f45a144 2017-09-05 16:33:37
showCache(tmpDir, userTags = c("^a$")) # regular expression ... "a" exactly
#> artifact tagKey #> 1: 009e7b31957b151903fe6de1c7719e28 format #> 2: 009e7b31957b151903fe6de1c7719e28 name #> 3: 009e7b31957b151903fe6de1c7719e28 class #> 4: 009e7b31957b151903fe6de1c7719e28 date #> 5: 009e7b31957b151903fe6de1c7719e28 objectName #> 6: 009e7b31957b151903fe6de1c7719e28 function #> 7: 009e7b31957b151903fe6de1c7719e28 object.size #> 8: 009e7b31957b151903fe6de1c7719e28 accessed #> 9: 009e7b31957b151903fe6de1c7719e28 cacheId #> tagValue createdDate #> 1: rda 2017-09-05 16:33:37 #> 2: Cache 2017-09-05 16:33:37 #> 3: numeric 2017-09-05 16:33:37 #> 4: 2017-09-05 16:33:37 2017-09-05 16:33:37 #> 5: a 2017-09-05 16:33:37 #> 6: rnorm 2017-09-05 16:33:37 #> 7: 528 2017-09-05 16:33:37 #> 8: 2017-09-05 16:33:37 2017-09-05 16:33:37 #> 9: 6c02ed3587ff36e0f232dc296099540b 2017-09-05 16:33:37
showCache(tmpDir, userTags = c("runif")) # show only cached objects made during runif call
#> artifact tagKey #> 1: 5a73ac00c3fdb4a0ab75c382af02ab58 format #> 2: 5a73ac00c3fdb4a0ab75c382af02ab58 name #> 3: 5a73ac00c3fdb4a0ab75c382af02ab58 class #> 4: 5a73ac00c3fdb4a0ab75c382af02ab58 date #> 5: 5a73ac00c3fdb4a0ab75c382af02ab58 objectName #> 6: 5a73ac00c3fdb4a0ab75c382af02ab58 function #> 7: 5a73ac00c3fdb4a0ab75c382af02ab58 object.size #> 8: 5a73ac00c3fdb4a0ab75c382af02ab58 accessed #> 9: 5a73ac00c3fdb4a0ab75c382af02ab58 cacheId #> tagValue createdDate #> 1: rda 2017-09-05 16:33:37 #> 2: Cache 2017-09-05 16:33:37 #> 3: numeric 2017-09-05 16:33:37 #> 4: 2017-09-05 16:33:37 2017-09-05 16:33:37 #> 5: b 2017-09-05 16:33:37 #> 6: runif 2017-09-05 16:33:37 #> 7: 528 2017-09-05 16:33:37 #> 8: 2017-09-05 16:33:37 2017-09-05 16:33:37 #> 9: 9dd2494a488858266cd45d230f45a144 2017-09-05 16:33:37
clearCache(tmpDir, userTags = c("runif")) # remove only cached objects made during runif call showCache(tmpDir) # only those made during rnorm call
#> artifact tagKey #> 1: 009e7b31957b151903fe6de1c7719e28 format #> 2: 009e7b31957b151903fe6de1c7719e28 name #> 3: 009e7b31957b151903fe6de1c7719e28 class #> 4: 009e7b31957b151903fe6de1c7719e28 date #> 5: 009e7b31957b151903fe6de1c7719e28 objectName #> 6: 009e7b31957b151903fe6de1c7719e28 function #> 7: 009e7b31957b151903fe6de1c7719e28 object.size #> 8: 009e7b31957b151903fe6de1c7719e28 accessed #> 9: 009e7b31957b151903fe6de1c7719e28 cacheId #> tagValue createdDate #> 1: rda 2017-09-05 16:33:37 #> 2: Cache 2017-09-05 16:33:37 #> 3: numeric 2017-09-05 16:33:37 #> 4: 2017-09-05 16:33:37 2017-09-05 16:33:37 #> 5: a 2017-09-05 16:33:37 #> 6: rnorm 2017-09-05 16:33:37 #> 7: 528 2017-09-05 16:33:37 #> 8: 2017-09-05 16:33:37 2017-09-05 16:33:37 #> 9: 6c02ed3587ff36e0f232dc296099540b 2017-09-05 16:33:37
clearCache(tmpDir) ## Example 2: using the "accessed" tag ranNumsA <- Cache(rnorm, 4, cacheRepo = tmpDir, userTags = "objectName:a") ranNumsB <- Cache(runif, 4, cacheRepo = tmpDir, userTags = "objectName:b") # access it again, but "later" Sys.sleep(1) ranNumsA <- Cache(rnorm, 4, cacheRepo = tmpDir, userTags = "objectName:a")
#> loading cached result from previous rnorm call.
wholeCache <- showCache(tmpDir) # keep only items accessed "recently" (i.e., only objectName:a) onlyRecentlyAccessed <- showCache(tmpDir, userTags = max(wholeCache[tagKey == "accessed"]$tagValue)) # inverse join with 2 data.tables ... using: a[!b] # i.e., return all of wholeCache that was not recently accessed toRemove <- unique(wholeCache[!onlyRecentlyAccessed], by = "artifact")$artifact clearCache(tmpDir, toRemove) # remove ones not recently accessed showCache(tmpDir) # still has more recently accessed
#> artifact tagKey #> 1: 52bcf1f614e547e5652d286d6249a411 format #> 2: 52bcf1f614e547e5652d286d6249a411 name #> 3: 52bcf1f614e547e5652d286d6249a411 class #> 4: 52bcf1f614e547e5652d286d6249a411 date #> 5: 52bcf1f614e547e5652d286d6249a411 objectName #> 6: 52bcf1f614e547e5652d286d6249a411 function #> 7: 52bcf1f614e547e5652d286d6249a411 object.size #> 8: 52bcf1f614e547e5652d286d6249a411 accessed #> 9: 52bcf1f614e547e5652d286d6249a411 cacheId #> 10: 52bcf1f614e547e5652d286d6249a411 accessed #> tagValue createdDate #> 1: rda 2017-09-05 16:33:37 #> 2: Cache 2017-09-05 16:33:37 #> 3: numeric 2017-09-05 16:33:37 #> 4: 2017-09-05 16:33:37 2017-09-05 16:33:37 #> 5: a 2017-09-05 16:33:37 #> 6: rnorm 2017-09-05 16:33:37 #> 7: 528 2017-09-05 16:33:37 #> 8: 2017-09-05 16:33:37 2017-09-05 16:33:37 #> 9: 6c02ed3587ff36e0f232dc296099540b 2017-09-05 16:33:37 #> 10: 2017-09-05 16:33:38 2017-09-05 16:33:38
clearCache(tmpDir) ## Example 3: using keepCache ranNumsA <- Cache(rnorm, 4, cacheRepo = tmpDir, userTags = "objectName:a") ranNumsB <- Cache(runif, 4, cacheRepo = tmpDir, userTags = "objectName:b") # keep only those cached items from the last 24 hours oneDay <- 60 * 60 * 24 keepCache(tmpDir, after = Sys.time() - oneDay)
#> artifact tagKey #> 1: 1c86b77fd749c361e3cfd9cd7189d7cd format #> 2: 1c86b77fd749c361e3cfd9cd7189d7cd name #> 3: 1c86b77fd749c361e3cfd9cd7189d7cd class #> 4: 1c86b77fd749c361e3cfd9cd7189d7cd date #> 5: 1c86b77fd749c361e3cfd9cd7189d7cd objectName #> 6: 1c86b77fd749c361e3cfd9cd7189d7cd function #> 7: 1c86b77fd749c361e3cfd9cd7189d7cd object.size #> 8: 1c86b77fd749c361e3cfd9cd7189d7cd accessed #> 9: 1c86b77fd749c361e3cfd9cd7189d7cd cacheId #> 10: 253ea5739e2ab953e683a960b74c13c3 format #> 11: 253ea5739e2ab953e683a960b74c13c3 name #> 12: 253ea5739e2ab953e683a960b74c13c3 class #> 13: 253ea5739e2ab953e683a960b74c13c3 date #> 14: 253ea5739e2ab953e683a960b74c13c3 objectName #> 15: 253ea5739e2ab953e683a960b74c13c3 function #> 16: 253ea5739e2ab953e683a960b74c13c3 object.size #> 17: 253ea5739e2ab953e683a960b74c13c3 accessed #> 18: 253ea5739e2ab953e683a960b74c13c3 cacheId #> tagValue createdDate #> 1: rda 2017-09-05 16:33:38 #> 2: Cache 2017-09-05 16:33:38 #> 3: numeric 2017-09-05 16:33:38 #> 4: 2017-09-05 16:33:38 2017-09-05 16:33:38 #> 5: b 2017-09-05 16:33:38 #> 6: runif 2017-09-05 16:33:38 #> 7: 528 2017-09-05 16:33:38 #> 8: 2017-09-05 16:33:38 2017-09-05 16:33:38 #> 9: 9dd2494a488858266cd45d230f45a144 2017-09-05 16:33:38 #> 10: rda 2017-09-05 16:33:38 #> 11: Cache 2017-09-05 16:33:38 #> 12: numeric 2017-09-05 16:33:38 #> 13: 2017-09-05 16:33:38 2017-09-05 16:33:38 #> 14: a 2017-09-05 16:33:38 #> 15: rnorm 2017-09-05 16:33:38 #> 16: 528 2017-09-05 16:33:38 #> 17: 2017-09-05 16:33:38 2017-09-05 16:33:38 #> 18: 6c02ed3587ff36e0f232dc296099540b 2017-09-05 16:33:38
# Keep all Cache items created with an rnorm() call keepCache(tmpDir, userTags = "rnorm")
#> artifact tagKey #> 1: 253ea5739e2ab953e683a960b74c13c3 format #> 2: 253ea5739e2ab953e683a960b74c13c3 name #> 3: 253ea5739e2ab953e683a960b74c13c3 class #> 4: 253ea5739e2ab953e683a960b74c13c3 date #> 5: 253ea5739e2ab953e683a960b74c13c3 objectName #> 6: 253ea5739e2ab953e683a960b74c13c3 function #> 7: 253ea5739e2ab953e683a960b74c13c3 object.size #> 8: 253ea5739e2ab953e683a960b74c13c3 accessed #> 9: 253ea5739e2ab953e683a960b74c13c3 cacheId #> tagValue createdDate #> 1: rda 2017-09-05 16:33:38 #> 2: Cache 2017-09-05 16:33:38 #> 3: numeric 2017-09-05 16:33:38 #> 4: 2017-09-05 16:33:38 2017-09-05 16:33:38 #> 5: a 2017-09-05 16:33:38 #> 6: rnorm 2017-09-05 16:33:38 #> 7: 528 2017-09-05 16:33:38 #> 8: 2017-09-05 16:33:38 2017-09-05 16:33:38 #> 9: 6c02ed3587ff36e0f232dc296099540b 2017-09-05 16:33:38
# Remove all Cache items that happened within a rnorm() call clearCache(tmpDir, userTags = "rnorm") showCache(tmpDir) ## empty
#> Empty data.table (0 rows) of 3 cols: md5hash,name,createdDate
## Example 4: searching for multiple objects in the cache # default userTags is "and" matching; for "or" matching use | ranNumsA <- Cache(runif, 4, cacheRepo = tmpDir, userTags = "objectName:a") ranNumsB <- Cache(rnorm, 4, cacheRepo = tmpDir, userTags = "objectName:b") # show all objects (runif and rnorm in this case) showCache(tmpDir)
#> artifact tagKey #> 1: 9e769122f97c46564f56cbb45bb92269 format #> 2: 9e769122f97c46564f56cbb45bb92269 name #> 3: 9e769122f97c46564f56cbb45bb92269 class #> 4: 9e769122f97c46564f56cbb45bb92269 date #> 5: 9e769122f97c46564f56cbb45bb92269 objectName #> 6: 9e769122f97c46564f56cbb45bb92269 function #> 7: 9e769122f97c46564f56cbb45bb92269 object.size #> 8: 9e769122f97c46564f56cbb45bb92269 accessed #> 9: 9e769122f97c46564f56cbb45bb92269 cacheId #> 10: e990b492c24ec313bf00147148ef85f2 format #> 11: e990b492c24ec313bf00147148ef85f2 name #> 12: e990b492c24ec313bf00147148ef85f2 class #> 13: e990b492c24ec313bf00147148ef85f2 date #> 14: e990b492c24ec313bf00147148ef85f2 objectName #> 15: e990b492c24ec313bf00147148ef85f2 function #> 16: e990b492c24ec313bf00147148ef85f2 object.size #> 17: e990b492c24ec313bf00147148ef85f2 accessed #> 18: e990b492c24ec313bf00147148ef85f2 cacheId #> tagValue createdDate #> 1: rda 2017-09-05 16:33:39 #> 2: Cache 2017-09-05 16:33:39 #> 3: numeric 2017-09-05 16:33:39 #> 4: 2017-09-05 16:33:39 2017-09-05 16:33:39 #> 5: b 2017-09-05 16:33:39 #> 6: rnorm 2017-09-05 16:33:39 #> 7: 528 2017-09-05 16:33:39 #> 8: 2017-09-05 16:33:39 2017-09-05 16:33:39 #> 9: 6c02ed3587ff36e0f232dc296099540b 2017-09-05 16:33:39 #> 10: rda 2017-09-05 16:33:38 #> 11: Cache 2017-09-05 16:33:38 #> 12: numeric 2017-09-05 16:33:38 #> 13: 2017-09-05 16:33:38 2017-09-05 16:33:38 #> 14: a 2017-09-05 16:33:38 #> 15: runif 2017-09-05 16:33:38 #> 16: 528 2017-09-05 16:33:38 #> 17: 2017-09-05 16:33:38 2017-09-05 16:33:38 #> 18: 9dd2494a488858266cd45d230f45a144 2017-09-05 16:33:38
# show objects that are both runif and rnorm # (i.e., none in this case, because objecs are either or, not both) showCache(tmpDir, userTags = c("runif", "rnorm")) ## empty
#> Empty data.table (0 rows) of 4 cols: artifact,tagKey,tagValue,createdDate
# show objects that are either runif or rnorm ("or" search) showCache(tmpDir, userTags = "runif|rnorm")
#> artifact tagKey #> 1: 9e769122f97c46564f56cbb45bb92269 format #> 2: 9e769122f97c46564f56cbb45bb92269 name #> 3: 9e769122f97c46564f56cbb45bb92269 class #> 4: 9e769122f97c46564f56cbb45bb92269 date #> 5: 9e769122f97c46564f56cbb45bb92269 objectName #> 6: 9e769122f97c46564f56cbb45bb92269 function #> 7: 9e769122f97c46564f56cbb45bb92269 object.size #> 8: 9e769122f97c46564f56cbb45bb92269 accessed #> 9: 9e769122f97c46564f56cbb45bb92269 cacheId #> 10: e990b492c24ec313bf00147148ef85f2 format #> 11: e990b492c24ec313bf00147148ef85f2 name #> 12: e990b492c24ec313bf00147148ef85f2 class #> 13: e990b492c24ec313bf00147148ef85f2 date #> 14: e990b492c24ec313bf00147148ef85f2 objectName #> 15: e990b492c24ec313bf00147148ef85f2 function #> 16: e990b492c24ec313bf00147148ef85f2 object.size #> 17: e990b492c24ec313bf00147148ef85f2 accessed #> 18: e990b492c24ec313bf00147148ef85f2 cacheId #> tagValue createdDate #> 1: rda 2017-09-05 16:33:39 #> 2: Cache 2017-09-05 16:33:39 #> 3: numeric 2017-09-05 16:33:39 #> 4: 2017-09-05 16:33:39 2017-09-05 16:33:39 #> 5: b 2017-09-05 16:33:39 #> 6: rnorm 2017-09-05 16:33:39 #> 7: 528 2017-09-05 16:33:39 #> 8: 2017-09-05 16:33:39 2017-09-05 16:33:39 #> 9: 6c02ed3587ff36e0f232dc296099540b 2017-09-05 16:33:39 #> 10: rda 2017-09-05 16:33:38 #> 11: Cache 2017-09-05 16:33:38 #> 12: numeric 2017-09-05 16:33:38 #> 13: 2017-09-05 16:33:38 2017-09-05 16:33:38 #> 14: a 2017-09-05 16:33:38 #> 15: runif 2017-09-05 16:33:38 #> 16: 528 2017-09-05 16:33:38 #> 17: 2017-09-05 16:33:38 2017-09-05 16:33:38 #> 18: 9dd2494a488858266cd45d230f45a144 2017-09-05 16:33:38
# keep only objects that are either runif or rnorm ("or" search) keepCache(tmpDir, userTags = "runif|rnorm")
#> artifact tagKey #> 1: 9e769122f97c46564f56cbb45bb92269 format #> 2: 9e769122f97c46564f56cbb45bb92269 name #> 3: 9e769122f97c46564f56cbb45bb92269 class #> 4: 9e769122f97c46564f56cbb45bb92269 date #> 5: 9e769122f97c46564f56cbb45bb92269 objectName #> 6: 9e769122f97c46564f56cbb45bb92269 function #> 7: 9e769122f97c46564f56cbb45bb92269 object.size #> 8: 9e769122f97c46564f56cbb45bb92269 accessed #> 9: 9e769122f97c46564f56cbb45bb92269 cacheId #> 10: e990b492c24ec313bf00147148ef85f2 format #> 11: e990b492c24ec313bf00147148ef85f2 name #> 12: e990b492c24ec313bf00147148ef85f2 class #> 13: e990b492c24ec313bf00147148ef85f2 date #> 14: e990b492c24ec313bf00147148ef85f2 objectName #> 15: e990b492c24ec313bf00147148ef85f2 function #> 16: e990b492c24ec313bf00147148ef85f2 object.size #> 17: e990b492c24ec313bf00147148ef85f2 accessed #> 18: e990b492c24ec313bf00147148ef85f2 cacheId #> tagValue createdDate #> 1: rda 2017-09-05 16:33:39 #> 2: Cache 2017-09-05 16:33:39 #> 3: numeric 2017-09-05 16:33:39 #> 4: 2017-09-05 16:33:39 2017-09-05 16:33:39 #> 5: b 2017-09-05 16:33:39 #> 6: rnorm 2017-09-05 16:33:39 #> 7: 528 2017-09-05 16:33:39 #> 8: 2017-09-05 16:33:39 2017-09-05 16:33:39 #> 9: 6c02ed3587ff36e0f232dc296099540b 2017-09-05 16:33:39 #> 10: rda 2017-09-05 16:33:38 #> 11: Cache 2017-09-05 16:33:38 #> 12: numeric 2017-09-05 16:33:38 #> 13: 2017-09-05 16:33:38 2017-09-05 16:33:38 #> 14: a 2017-09-05 16:33:38 #> 15: runif 2017-09-05 16:33:38 #> 16: 528 2017-09-05 16:33:38 #> 17: 2017-09-05 16:33:38 2017-09-05 16:33:38 #> 18: 9dd2494a488858266cd45d230f45a144 2017-09-05 16:33:38
clearCache(tmpDir) ## Example 5: using caching to speed up rerunning expensive computations ras <- raster(extent(0, 100, 0, 100), res = 1, vals = sample(1:5, replace = TRUE, size = 1e4), crs = "+proj=lcc +lat_1=48 +lat_2=33 +lon_0=-100 +ellps=WGS84") # A slow operation, like GIS operation notCached <- suppressWarnings( # project raster generates warnings when run non-interactively projectRaster(ras, crs = crs(ras), res = 5, cacheRepo = tmpDir) ) cached <- suppressWarnings( # project raster generates warnings when run non-interactively Cache(projectRaster, ras, crs = crs(ras), res = 5, cacheRepo = tmpDir) ) # second time is much faster reRun <- suppressWarnings( # project raster generates warnings when run non-interactively Cache(projectRaster, ras, crs = crs(ras), res = 5, cacheRepo = tmpDir) )
#> loading cached result from previous projectRaster call.
# recovered cached version is same as non-cached version all.equal(notCached, reRun) ## TRUE
#> [1] TRUE
## Example 6: working with file paths # if passing a character string, it will take 2 complete passes to before # a cached copy is used when it is a save event (read or load is different) obj <- 1:10 fname <- tempfile(fileext = ".RData") Cache(saveRDS, obj, file = fname, cacheRepo = tmpDir)
#> NULL
Cache(saveRDS, obj, file = fname, cacheRepo = tmpDir)
#> NULL
Cache(saveRDS, obj, file = fname, cacheRepo = tmpDir) # cached copy is loaded
#> loading cached result from previous saveRDS call.
#> [1] "NULL" #> attr(,"tags") #> [1] "cacheId:46db9ac49c0d1d44463ac3c5dfe3119a" #> attr(,"call") #> [1] ""
# however, using asPath(), cached version retrieved after being run once fname1 <- tempfile(fileext = ".RData") Cache(saveRDS, obj, file = asPath(fname1), cacheRepo = tmpDir)
#> NULL
Cache(saveRDS, obj, file = asPath(fname1), cacheRepo = tmpDir) # cached copy is loaded
#> loading cached result from previous saveRDS call.
#> [1] "NULL" #> attr(,"tags") #> [1] "cacheId:e55a7145bb038052c15955e7f5f8e52c" #> attr(,"call") #> [1] ""
clearCache(tmpDir) ## cleanup unlink(c("filename.rda", "filename1.rda")) unlink(dirname(tmpDir), recursive = TRUE)