A builder of {@link Cache} instances having any combination of the following features:
Usage example:
{@code CacheThese features are all optional.graphs = CacheBuilder.newBuilder() .concurrencyLevel(4) .weakKeys() .maximumSize(10000) .expireAfterWrite(10, TimeUnit.MINUTES) .build(}new CacheLoader () public Graph load(Key key) throws AnyException { return createExpensiveGraph(key); } });}
The returned cache is implemented as a hash table with similar performance characteristics to {@link ConcurrentHashMap}. It implements the optional operations {@link Cache#invalidate}, {@link Cache#invalidateAll}, {@link Cache#size}, {@link Cache#stats}, and {@link Cache#asMap}, with the following qualifications:
Note: by default, the returned cache uses equality comparisons (the {@link Object#equals equals} method) to determine equality for keys or values. However, if{@link #weakKeys} was specified, the cache uses identity ({@code ==}) comparisons instead for keys. Likewise, if {@link #weakValues} or {@link #softValues} wasspecified, the cache uses identity comparisons for values.
If soft or weak references were requested, it is possible for a key or value present in the the cache to be reclaimed by the garbage collector. If this happens, the entry automatically disappears from the cache. A partially-reclaimed entry is never exposed to the user.
The caches produced by {@code CacheBuilder} are serializable, and the deserialized cachesretain all the configuration properties of the original cache. @param < K> the base key type for all caches created by this builder @param < V> the base value type for all caches created by this builder @author Charles Fry @author Kevin Bourrillion @since Guava release 10
Warning: This is a facade provided for use by user code, not for implementation by user code. User implementations of this interface are highly likely to be incompatible with future releases of the product at both binary and source levels.
Property Summary | |
object provider | The object responsible for providing objects to the cache when the object is not present. |
max count | The maximum number of entries allowed in the cache. This must be greater than 0. |
group organizer | The object responsible for selecting the group into which a newly created {@link CacheEntry} is to be placed. |
clock | The object responsible for providing times to the cache, typically only used when testing. |
expiration checker | The object responsible for checking whether an entry has expired. If this is not set then entries will never expire. |
|
|
|
|
|
|
|
|
|
|
|
|