KEYTYPE - The cache key typeVALUETYPE - The cache value type@ThreadSafe public abstract class AbstractCache<KEYTYPE,VALUETYPE> extends Object implements IMutableCache<KEYTYPE,VALUETYPE>
ICache| Modifier and Type | Field and Description |
|---|---|
protected IMutableStatisticsHandlerCache |
m_aCacheAccessStats |
protected SimpleReadWriteLock |
m_aRWLock |
static String |
STATISTICS_PREFIX
The prefix to be used for statistics elements
|
| Constructor and Description |
|---|
AbstractCache(int nMaxSize,
String sCacheName) |
AbstractCache(String sCacheName) |
| Modifier and Type | Method and Description |
|---|---|
EChange |
clearCache()
Remove all cached elements.
|
protected Map<KEYTYPE,VALUETYPE> |
createCache()
Create a new cache map.
|
VALUETYPE |
getFromCache(KEYTYPE aKey)
Get the cached value associated with the passed key.
|
protected VALUETYPE |
getFromCacheNoStats(KEYTYPE aKey) |
protected VALUETYPE |
getFromCacheNoStatsNotLocked(KEYTYPE aKey) |
protected VALUETYPE |
getFromCacheNotLocked(KEYTYPE aKey) |
int |
getMaxSize() |
String |
getName() |
int |
getSize() |
boolean |
hasMaxSize() |
boolean |
isEmpty() |
boolean |
isNotEmpty() |
protected void |
putInCache(KEYTYPE aKey,
VALUETYPE aValue)
Put a new value into the cache.
|
protected void |
putInCacheNotLocked(KEYTYPE aKey,
VALUETYPE aValue)
Put a new value into the cache.
|
EChange |
removeFromCache(KEYTYPE aKey)
Remove the given key from the cache.
|
String |
toString() |
public static final String STATISTICS_PREFIX
protected final SimpleReadWriteLock m_aRWLock
protected final IMutableStatisticsHandlerCache m_aCacheAccessStats
public AbstractCache(@CheckForSigned int nMaxSize, @Nonnull @Nonempty String sCacheName)
public final int getMaxSize()
public final boolean hasMaxSize()
@Nonnull @ReturnsMutableCopy @OverrideOnDemand protected Map<KEYTYPE,VALUETYPE> createCache()
null.@MustBeLocked(value=WRITE) protected final void putInCacheNotLocked(@Nonnull KEYTYPE aKey, @Nonnull VALUETYPE aValue)
aKey - The cache key. May not be null.aValue - The cache value. May not be null.protected final void putInCache(@Nonnull KEYTYPE aKey, @Nonnull VALUETYPE aValue)
aKey - The cache key. May not be null.aValue - The cache value. May not be null.@MustBeLocked(value=READ) @Nullable protected final VALUETYPE getFromCacheNoStatsNotLocked(@Nullable KEYTYPE aKey)
@Nullable @OverridingMethodsMustInvokeSuper protected final VALUETYPE getFromCacheNoStats(@Nullable KEYTYPE aKey)
@Nullable protected final VALUETYPE getFromCacheNotLocked(@Nullable KEYTYPE aKey)
@Nullable @OverridingMethodsMustInvokeSuper public VALUETYPE getFromCache(KEYTYPE aKey)
ICachegetFromCache in interface ICache<KEYTYPE,VALUETYPE>aKey - The key to be looked up. May be nullable or not -
depends upon the implementation.null if no such value is in the cache.@Nonnull @OverridingMethodsMustInvokeSuper public EChange removeFromCache(KEYTYPE aKey)
IMutableCacheremoveFromCache in interface IMutableCache<KEYTYPE,VALUETYPE>aKey - The key to be removed. May be nullable or not - depends
upon the implementation.EChange.CHANGED upon success, EChange.UNCHANGED if
the key was not within the cache,@Nonnull @OverridingMethodsMustInvokeSuper public EChange clearCache()
IMutableCacheclearCache in interface IMutableCache<KEYTYPE,VALUETYPE>EChange.@Nonnegative public int getSize()
public boolean isEmpty()
isEmpty in interface IHasSizetrue if no items are present, false if at
least a single item is present.IHasSize.getSize()public boolean isNotEmpty()
Copyright © 2014–2015 Philip Helger. All rights reserved.