memoise icon indicating copy to clipboard operation
memoise copied to clipboard

Using Memoise with RESTful API Calls that Require Unique Access Token

Open masato-yoshihara opened this issue 4 years ago • 3 comments

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?

masato-yoshihara avatar Nov 24 '20 04:11 masato-yoshihara

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.

jimhester avatar Nov 30 '20 14:11 jimhester

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?

masato-yoshihara avatar Dec 01 '20 21:12 masato-yoshihara

Yes!

jimhester avatar Dec 02 '20 13:12 jimhester