June 2018
Intermediate to advanced
280 pages
7h 46m
English
In the following example, we are going to reuse the Fibonacci code and add a Guava cache. The cache will hold the returned values of Fibonacci while the key is the input number. The cache is configured to limit the memory footprint both in size and time:
importstatic cyclops.control.Trampoline.done;importstatic cyclops.control.Trampoline.more;import java.math.BigInteger;import java.util.Arrays;import java.util.List;import java.util.concurrent.TimeUnit;import com.google.common.cache.Cache;import com.google.common.cache.CacheBuilder;import cyclops.async.LazyReact;import cyclops.control.Trampoline;publicclass Main { public BigInteger fib(BigInteger n) { return fibonacci(n, BigInteger.ZERO, BigInteger.ONE).get(); } public Trampoline<BigInteger> ...Read now
Unlock full access