I know of this one http://onjava.com/pub/a/onjava/2003/08/20/memoization.html but is there anything else?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Yes. Use caches from Guava.
Example:
To memoize functions without parameters, use Guava's
Suppliers.memoize(Supplier)
. For functions with parameters, useCacheBuilder.build(CacheLoader)
with parameter value objects as keys.Memoization is also easy with plain simple typesafe Java.
You can do it from scratch with the following reusable classes.
I use these as caches whose lifespan are the request on a webapp.
Of course use the Guava
MapMaker
if you need an eviction strategy or more features like synchronization.If you need to memoize a method with many parameters, just put the parameters in a list with both techniques, and pass that list as the single parameter.
And this is used like this