V
- the base value type for all caches created by this builderpublic abstract class CacheBuilder<V extends Serializable> extends Object
LoadingCache
and Cache
instances.
Applications must implement the build(String)
and build(String, CacheLoader)
methods, to provide a Cache
and
LoadingCache
implementation. It can either use a standard Guava implementation, or an application specific cache.
CacheFactory
Constructor and Description |
---|
CacheBuilder() |
Modifier and Type | Method and Description |
---|---|
abstract com.google.common.cache.Cache<String,V> |
build(String title)
Builds a synchronous cache which does not automatically load values when keys are requested.
|
abstract com.google.common.cache.LoadingCache<String,V> |
build(String title,
com.google.common.cache.CacheLoader<String,V> loader)
Creates a synchronous cache, which either returns an already-loaded value for a given key or atomically computes or retrieves it using the
supplied CacheLoader.
|
CacheBuilder<V> |
expireAfterWrite(long duration,
TimeUnit unit)
Specifies that each entry should be automatically removed from the cache once a fixed duration has elapsed after the entry's creation, or the
most recent replacement of its value.
|
protected long |
getExpireAfterWriteNanos()
Returns the duration in nanoseconds after an entry is created that it should be automatically removed.
|
public CacheBuilder<V> expireAfterWrite(long duration, TimeUnit unit)
duration
- the length of time after an entry is created that it should be automatically removedunit
- the unit that duration is expressed inpublic abstract com.google.common.cache.Cache<String,V> build(String title)
Consider build(String, CacheLoader)
instead, if it is feasible to implement a CacheLoader.
title
- the cache titlepublic abstract com.google.common.cache.LoadingCache<String,V> build(String title, com.google.common.cache.CacheLoader<String,V> loader)
title
- the cache titleloader
- the cache loader used to obtain new valuesprotected long getExpireAfterWriteNanos()