-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using memoise
to enhance performance and reduce network traffic
#366
Comments
+1 Thanks for the prompt @rburghol -- I need to think about how to best use this kind of thing in the package. nhdplusTools has undergone a lot of change recently and needs some further clean up. |
I've introduced memoise as a dependency for something else and will start working it in over time. Sorry this has been on the back burner for a while. |
I roughed in an implementation that I'm pretty happy with. No doubt there'll be issues, but it's a good start. See #364. You can now set environment variables to control cache location (memory or disc) and duration. I've wrapped functions that make cacheable requests in memoise and use the pattern discussed above to control cache behavior. It defaults to a filesystem cache for one day. |
A start is in now -- please test and open follow up issues if things are not right. |
This example is based on some code that @dblodgett-usgs shared in an issue on cacheing NWIS queries. DOI-USGS/dataRetrieval#681
Setup
Essentially, one selects a dat directory to store caches, and writes a wrapper around
nhdplustools
queries using the packagememoise
. I used a 1-year timeout since I figured that this data changes slowly, but the veracity of that assumption is less important than the technique:Retrieving point and basin info
After initial setup, calling these functions more than once in a year will see it searching the cache before going out to get fresh data.
Testing
memoised
plots successfully re-render within a single Rstudio session.memoised
plots (3-5 seconds in my test)The text was updated successfully, but these errors were encountered: