cache for Dummies (prepInputs)

Skip to first unread message

Tati Micheletti

Aug 16, 2018, 2:02:06 PM8/16/18
to SpaDES Users
HI all,

I wanted to know how can I find the caching of a specific shapefile that was downloaded and loaded using prepInputs with the userTags. I tried the targetfile, the url, and the archive of the respective shapefile, but it returns a table with 0 rows. I know I can sort my problem out "immediatly" by skipping the cache (useCache = FALSE), but I was wondering how I can actually delete the cache of this specific shapefile.

Thanks a lot!

Alex Chubaty

Aug 16, 2018, 6:07:22 PM8/16/18
to SpaDES Users
What have you tried? Something like the following usually does the trick:

reproducible::clearCache("path/to/cache", userTags = "something")

Tati Micheletti

Aug 16, 2018, 6:10:14 PM8/16/18
to SpaDES Users
Was the first thing I did.

reproducible::showCache("path/to/cache", userTags = "targetfile")
reproducible::showCache("path/to/cache", userTags = "archive")
reproducible::showCache("path/to/cache", userTags = "")

but none of these found the cache for this specific target file...

Alex Chubaty

Aug 16, 2018, 6:22:50 PM8/16/18
to SpaDES Users
I don't think you can use it to search for arguments to a function that was Cached (just the function name). Did you pass a userTags argument when you called Cache()?

Tati Micheletti

Aug 16, 2018, 6:28:37 PM8/16/18
to SpaDES Users
No, I didn't... =/
The problem is that I call prepInputs several times, and if I clearCache on it it will erase several things that are being called over and over. Ok, next time I will pass a userTag on it. Thanks, Alex! :)

Eliot McIntire

Aug 18, 2018, 11:40:23 PM8/18/18
to SpaDES Users
Also, I use "after" very often. If I run a line that has a Cache, and it is pulling in a cached copy that I don't want, then:

clearCache("/path/to/repo", after = Sys.time() - 20) 

That will remove all items in the Cache database that were "hit" in the last 20 seconds.

But, @AlexChubaty is sort of correct... you *can* use arguments if you convert them to their hash manually using .robustDigest(arg) to find its hash value. 

a <- Cache(rnorm, 4000) 
b <- Cache(rnorm, 5000)
hashVal <- .robustDigest(5000) # get only the one that had 5000 as its argument value
showCache(userTags = hashVal) # shows the cached elements that have 5000 as an argument
clearCache(userTags = hashVal) # deletes it
showCache() # only the one with 4000 is left

Other ways to find cached elements: The function name (e.g., shapefile), time stamp (including both write and read to Cache), also, object.size has been useful when I needed to detect failed function calls (the success would have been a large raster object, and the failed ones were <1000 bytes).
Reply all
Reply to author
0 new messages