Package net.i2p.util
Class TryCache<T>
- java.lang.Object
-
- net.i2p.util.TryCache<T>
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
TryCache.ObjectFactory<T>
Something that creates objects of the type cached by this cache
-
Constructor Summary
Constructors Constructor Description TryCache(TryCache.ObjectFactory<T> factory, int capacity)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.
-
-
-
Constructor Detail
-
TryCache
public TryCache(TryCache.ObjectFactory<T> factory, int capacity)
- Parameters:
factory
- to be used for creating new instancescapacity
- cache up to this many items
-
-
Method Detail
-
acquire
public T acquire()
- Returns:
- a cached or newly created item from this cache
-
release
public 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.
-
clear
public void clear()
Clears all cached items. This is the only method that blocks until it acquires the lock.
-
-