memoise
memoise copied to clipboard
Using Memoise with RESTful API Calls that Require Unique Access Token
I'm looking to use memoise in my R Shiny application with functions that will query our database on MongoDB Atlas using a RESTful API that requires a unique access token per session. For example:
#Calls to the RESTful API are made within the function.
getResults <- function(query, access_token){
#Code here!
}
getResultsMem <- memoise(getResults)
From what I understand, because memoise caches the function rather than the results, I'm having an issue where I can't use memoise since the access token changes every time that the user logs in. Since the database will only be updated once a year, memoise/caching is an ideal solution for my application. Is there a solution around this?
One way to work around this would be to read the access token from an environment variable rather than as a parameter. There currently is not a way to exclude a parameter from being included in the memoize hash.
Thanks so much for the response Jim! Out of curiosity, I noticed a parameter labeled omit_args in the development version of the memoise function. Once the newest version of the memoise package is published, would I be able to use that argument to have the memoise function ignore a parameter in a function?
Yes!