| Modifier and Type | Class and Description |
|---|---|
static interface | TryCache.ObjectFactory<T>Factory interface for creating new objects in TryCache. |
| Constructor and Description |
|---|
TryCache(TryCache.ObjectFactory<T> factory,
int capacity)TryCache. |
| Modifier and Type | Method and Description |
|---|---|
T | acquire()Acquire an object from the cache or create a new one. |
void | clear()Clear all cached items. |
long | getAcquireCount()Return total acquire() count (hits + misses). |
int | getCapacity()Return the current cache capacity. |
long | getDiscardCount()Return the number of release() calls that were discarded because
the cache was full. |
long | getLastUnderflowTime()Get the timestamp of the last underflow. |
long | getMissCount()Return the number of acquire() calls that found an empty cache
(misses required allocating a new object). |
long | getReleaseCount()Return total release() count (returned to cache). |
void | release(T item)Try to return the item to the cache. |
void | resize(int newCapacity)Resize the cache to a new capacity. |
void | shrink(int targetSize)Shrink the cache to the target size, evicting excess items. |
int | size()Get the current number of cached items. |
boolean | wasUnderfilled(long thresholdMillis)Check if the cache has been underfilled longer than the threshold. |
public TryCache(TryCache.ObjectFactory<T> factory, int capacity)
public T acquire()
public void clear()
public long getAcquireCount()
public int getCapacity()
public long getDiscardCount()
public long getLastUnderflowTime()
public long getMissCount()
public long getReleaseCount()
public void release(T item)
item - the itempublic void resize(int newCapacity)
newCapacity - the new maximum number of entriespublic void shrink(int targetSize)
targetSize - the desired maximum number of itemspublic int size()
public boolean wasUnderfilled(long thresholdMillis)
thresholdMillis - the threshold in milliseconds