public abstract static class PlayerStats.CachedStatistic<T>
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
protected T |
cached |
protected java.util.function.Supplier<T> |
fetcher |
protected long |
lastUpdateStarted |
| Modifier | Constructor and Description |
|---|---|
protected |
CachedStatistic(java.util.function.Supplier<T> fetcher) |
| Modifier and Type | Method and Description |
|---|---|
T |
getAndRequestUpdate() |
T |
getAndRequestUpdate(long maxCacheAge) |
T |
getCached()
Get the cached value
|
T |
getCachedOrRequest()
The cached value, querying the database only if there is nothing cached at all.
|
long |
getLastUpdate()
Deprecated.
|
long |
getLastUpdateStarted() |
void |
invalidateCache() |
void |
requestUpdate(@Nullable java.util.function.Consumer<T> callback) |
void |
requestUpdate(@Nullable java.util.function.Consumer<T> callback,
long maxCacheAgeMs)
Request an asynchronous update.
|
protected void |
setCached(T cached)
Update the cached value
|
static void |
shutdown()
Stops the query threads and waits for the queries still running.
|
protected volatile long lastUpdateStarted
protected volatile T cached
protected java.util.function.Supplier<T> fetcher
protected CachedStatistic(java.util.function.Supplier<T> fetcher)
public static void shutdown()
public T getCached()
public T getCachedOrRequest()
This is what reads such as placeholders should use. The values are filled in when the
player joins and refreshed by PlayerStats.refreshQueriedStats(BattleKit) every
time a fight of theirs is saved, so displaying one does not need a query of its own. The
fallback covers what those two do not, such as a kit created while the server is running
or an earlier query that failed; the cache age keeps it to one attempt per
'cached-stats-max-age' instead of one per read.
public T getAndRequestUpdate(long maxCacheAge)
public T getAndRequestUpdate()
protected void setCached(T cached)
public void invalidateCache()
public long getLastUpdateStarted()
@Deprecated public long getLastUpdate()
public void requestUpdate(@Nullable
@Nullable java.util.function.Consumer<T> callback,
long maxCacheAgeMs)
public void requestUpdate(@Nullable
@Nullable java.util.function.Consumer<T> callback)