-
Notifications
You must be signed in to change notification settings - Fork 58
Description
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.