Package VASSAL.tools.opcache
Class OpCache
java.lang.Object
VASSAL.tools.opcache.OpCache
A memory-sensitive cache for
Ops and their results.- Since:
- 3.1.0
- Author:
- Joel Uckelman
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()<V> Vget(OpCache.Key<V> key) Gets a value from the cache.<V> Vget(OpCache.Key<V> key, OpObserver<V> obs) Gets a value from the cache, possibly asynchronously.<V> Future<V> getFuture(OpCache.Key<V> key, OpObserver<V> obs) Gets aFuturefrom the cache.<V> VgetIfDone(OpCache.Key<V> key) Gets a value from the cache, if it is already calculated.
-
Field Details
-
cache
-
-
Constructor Details
-
OpCache
public OpCache()
-
-
Method Details
-
get
Gets a value from the cache.- Parameters:
key- theKeyfor which to retrieve a value- Returns:
- the value associated with
key
-
get
public <V> V get(OpCache.Key<V> key, OpObserver<V> obs) throws CancellationException, InterruptedException, ExecutionException Gets a value from the cache, possibly asynchronously.- Parameters:
key- theKeyfor which to retrieve a valueobs- theOpObserverto notify when the value is available- Returns:
- the value associated with
key - Throws:
CancellationException- if the request is cancelledInterruptedException- if the request is interruptedExecutionException- if the request fails
-
getFuture
Gets aFuturefrom the cache. Ifobs == null, then theOpassociated withkeywill be executed synchronously, and asynchronously otherwise.- Parameters:
key- theKeyfor which to retrieve aFutureobs- theOpObserverto notify when the value is available- Returns:
- the
Futureassociated withkey - Throws:
ExecutionException- if the request is synchronous and fails
-
getIfDone
Gets a value from the cache, if it is already calculated.- Parameters:
key- theKeyfor which to retrieve a value- Returns:
- the value associated with
key, ornull
-
clear
public void clear()
-