Skip to content

Conversation

@dkesh
Copy link

@dkesh dkesh commented Mar 19, 2015

This commit creates a new function has.cache( f, ... ) that returns TRUE or FALSE

I use memoisation extensively for network operations. It is sometimes useful to me to use a slow API if it has already been cached and a faster API if the slow API has not been cached. In this case, I want to test whether a function has been cached without actually running it.

jimhester pushed a commit that referenced this pull request Jan 19, 2016
@jimhester jimhester merged commit 15bd87b into r-lib:master Jan 22, 2016
@jimhester
Copy link
Member

Thanks for the PR! I renamed this function has_cache() and modified the API, it now returns a modified memoized function that simply returns a boolean value if the arguments have a cached value. This simplified the implementation (which has become more complicated after merging #14) and gives you the same auto completion of arguments. So from your example you can now do the following.

mem_sum <- memoise(sum)
has_cache(mem_sum)(1, 2, 3) # FALSE
#> [1] FALSE
mem_sum(1, 2, 3)
#> [1] 6
has_cache(mem_sum)(1, 2, 3) # TRUE
#> [1] TRUE

@dkesh
Copy link
Author

dkesh commented Jan 22, 2016

Thanks!

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

Successfully merging this pull request may close these issues.

2 participants