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

Option to avoid caching "invalid" objects? #138

Open
DarwinAwardWinner opened this issue Jul 12, 2022 · 1 comment
Open

Option to avoid caching "invalid" objects? #138

DarwinAwardWinner opened this issue Jul 12, 2022 · 1 comment

Comments

@DarwinAwardWinner
Copy link

We already have the ... arguments to memoise that can be used to define additional pre-call conditions on memoisation. However, in some cases I want certain return values not to be memoised. The example I'm working with now is memoising httr::GET. If the GET request fails, it doesn't throw an R error, it just returns a response object with a status code indicating failure, which would then be memoised and cause any further GET requests to the same URL to return the memoised failure. Ideally, I'd like to be able to supply a function or formula to be evaluated on the return value, and if it returns FALSE, the value should not be cached (and the corresponding key should probably be deleted from the cache as well if it exists). However, the value should still be returned as normal.

Currently I am implementing this with a wrapper that checks the status code and then does a drop_cache before returning if needed, but obviously caching the return value and then immediately deleting it from the cache isn't terribly efficient.

@baslat
Copy link

baslat commented Jun 22, 2023

@DarwinAwardWinner could you please share that wrapper? I have the same situation.

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