|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.evanmclean.evlib.cache.CacheBuilder
public class CacheBuilder
Builds caches to spec for a cache manager (see CacheManager.builder()
).
Default builder has the following properites:
ttl
of 10 seconds.refresh
of false
indicating expiry times are
never refreshed.max entries
equals 0).Caches include a refresh facility, which can effectively keep most used items in the cache while least used ones expire out of the cache. This is different to the default behaviour in which each item in the cache has a set lifetime (time-to-live).
Note that while you can change the expiry time on an existing cache, this only effects new values that are added to the cache. Existing values will always use the time to live value that was in effect when it was initially added to the cache.
Reference Types and Value DisposersEntries in a cache can be stored with either a strong, soft or weak reference.
A cache can also have a helper value disposer, that is called only any value
that is expired by reaching the end of its time to live, or by a call to
Map.clear()
. This is useful for cleaning up resources when a value
goes out of scope. Only caches that keep a strong reference type can have a
value disposer.
Method Summary | ||
---|---|---|
|
build(Class<?> cls)
Builds a cache with the current factory settings. |
|
|
build(String name)
Builds a cache with the current factory settings. |
|
|
buildOrGet(Class<?> cls)
Builds a cache (if it doesn't already exist) with the current factory settings. |
|
|
buildOrGet(String name)
Builds a cache (if it doesn't already exist) with the current factory settings. |
|
CacheBuilder |
disposer(CacheValueDisposer<?> value_disposer)
Object used to clean up cached values that expire or are removed via a call to Map.clear() . |
|
CacheReferenceType |
getCacheReferenceType()
Get the cache reference type that caches with be created with. |
|
int |
getMaxEntries()
The maximum number of entries caches with contain (0 for unlimited). |
|
long |
getTtlMillisec()
The time to live for each entry (in milliseconds). |
|
boolean |
isRefreshTtl()
True if retrieving a value from the cache refreshes its expiry time. |
|
CacheBuilder |
max(int max_entries)
Set the maximum number of entries caches will be allowed to contain (0 for unlimited). |
|
CacheBuilder |
nodisposer()
Set caches to have no value disposer. |
|
CacheBuilder |
norefresh()
Sets the cache to not refresh the expiry time of values when they are retrieved by calls like Map.get(Object) . |
|
CacheBuilder |
ref(CacheReferenceType cache_reference_type)
The reference type that will be used by caches for storing their values. |
|
CacheBuilder |
refresh()
Sets the cache to refresh the expiry time of values when they are retrieved by calls like Map.get(Object) . |
|
CacheBuilder |
refresh(boolean refresh_ttl)
Sets the cache to refresh the expiry time of values when they are retrieved by calls like Map.get(Object) . |
|
CacheBuilder |
reset()
Resets the builder to default values. |
|
CacheBuilder |
soft()
Values will be stored in created caches with a soft reference (see CacheReferenceType.SOFT ). |
|
CacheBuilder |
strong()
Values will be stored in created caches with a strong reference (see CacheReferenceType.STRONG ). |
|
CacheBuilder |
ttl(long ttl,
TimeUnit time_unit)
Set the time to live for values that will be used in the caches created. |
|
CacheBuilder |
weak()
Values will be stored in created caches with a weak reference (see CacheReferenceType.WEAK ). |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public <K,V> ConcurrentHashMapCache<K,V> build(Class<?> cls) throws CacheExistsException
K
- V
- cls
- The name of the cache will be the name of the class.
CacheExistsException
- Thrown if the cache already exists.public <K,V> ConcurrentHashMapCache<K,V> build(String name) throws CacheExistsException
K
- V
- name
- The name of the cache.
CacheExistsException
- Thrown if the cache already exists.public <K,V> ConcurrentHashMapCache<K,V> buildOrGet(Class<?> cls)
K
- V
- cls
- The name of the cache will be the name of the class.
public <K,V> ConcurrentHashMapCache<K,V> buildOrGet(String name)
K
- V
- name
- The name of the cache.
public CacheBuilder disposer(CacheValueDisposer<?> value_disposer)
Map.clear()
.
value_disposer
- Method to clean up expired values (may be null
).
public CacheReferenceType getCacheReferenceType()
public int getMaxEntries()
public long getTtlMillisec()
public boolean isRefreshTtl()
public CacheBuilder max(int max_entries)
max_entries
- The maximum number of entries caches will be allowed to contain (0
for unlimited).
public CacheBuilder nodisposer()
public CacheBuilder norefresh()
Map.get(Object)
.
public CacheBuilder ref(CacheReferenceType cache_reference_type)
cache_reference_type
- The reference type that will be used by caches for storing their
values.
public CacheBuilder refresh()
Map.get(Object)
.
public CacheBuilder refresh(boolean refresh_ttl)
Map.get(Object)
.
refresh_ttl
- True to refresh the expiry time of values when they are retrieved.
public CacheBuilder reset()
public CacheBuilder soft()
CacheReferenceType.SOFT
).
public CacheBuilder strong()
CacheReferenceType.STRONG
).
public CacheBuilder ttl(long ttl, TimeUnit time_unit)
ttl
- The time to live for values that will be used in the caches created.time_unit
- The time unit for ttl
.
public CacheBuilder weak()
CacheReferenceType.WEAK
).
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |