Modifier and Type | Class and Description |
---|---|
static interface |
TryCache.ObjectFactory<T>
Something that creates objects of the type cached by this cache
|
Modifier and Type | Field and Description |
---|---|
protected long |
_lastUnderflow |
protected int |
capacity |
protected List<T> |
items |
protected Lock |
lock |
Constructor and Description |
---|
TryCache(TryCache.ObjectFactory<T> factory,
int capacity) |
Modifier and Type | Method and Description |
---|---|
T |
acquire() |
void |
clear()
Clears all cached items.
|
void |
release(T item)
Tries to return this item to the cache but it may fail if
the cache has reached capacity or it's lock is held by
another thread.
|
protected final int capacity
protected final Lock lock
protected long _lastUnderflow
public TryCache(TryCache.ObjectFactory<T> factory, int capacity)
factory
- to be used for creating new instancescapacity
- cache up to this many itemspublic T acquire()
public void release(T item)
public void clear()