Skip to content
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 with RESTful API Calls that Require Unique Access Token #116

Open
masato-yoshihara opened this issue Nov 24, 2020 · 3 comments

Comments

@masato-yoshihara
Copy link

masato-yoshihara commented Nov 24, 2020

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?

@jimhester
Copy link
Member

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.

@masato-yoshihara
Copy link
Author

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?

@jimhester
Copy link
Member

Yes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants