java.lang.Object
io.ebeaninternal.server.cache.DefaultServerCache
- All Implemented Interfaces:
ServerCache
- Direct Known Subclasses:
DefaultServerQueryCache
The default cache implementation.
It is base on ConcurrentHashMap with periodic trimming using a TimerTask. The periodic trimming means that an LRU list does not have to be maintained.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classWraps the value to additionally hold createTime and lastAccessTime and hit counter.static final classComparator for sorting by last access sort, a copy of last access time that should not mutate during trim processing.final classRunnable that calls the eviction routine. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DefaultServerCache.CompareByLastAccessCompare by last access time (for LRU eviction).protected final CountMetricprotected final CountMetricprotected final CountMetricprotected final CountMetricprotected final CountMetricprotected final ReentrantLockprotected static final System.Loggerprotected final CountMetricprotected final Map<Object, SoftReference<DefaultServerCache.CacheEntry>> The underlying map (ConcurrentHashMap or similar)protected final intprotected final intprotected final intprotected final CountMetricprotected final AtomicLongprotected final Stringprotected final CountMetricprotected final CountMetricprotected final Stringprotected final intprotected final longprotected final CountMetric -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clear the cache.Return a value from the cache.protected DefaultServerCache.CacheEntrygetCacheEntry(Object key) Get the cache entry - override for query cache to validate dependent tables.longReturn the count of get hits.longReturn the count of get misses.getName()Return the name of the cache.protected intReturn the size to trim to based on the max size.inthitRatio()voidperiodicTrim(BackgroundExecutor executor) voidPut a value into the cache.voidvoidRemove an entry from the cache.voidRun the eviction based on Idle time, Time to live and LRU last access.intsize()Return the number of elements in the cache.statistics(boolean reset) protected ObjectUnwrap the cache entry - override for query cache to unwrap to the query result.voidvisit(MetricVisitor visitor) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.ebean.cache.ServerCache
getAll, removeAll, unwrap
-
Field Details
-
logger
-
BY_LAST_ACCESS
Compare by last access time (for LRU eviction). -
map
The underlying map (ConcurrentHashMap or similar) -
hitCount
-
missCount
-
putCount
-
removeCount
-
clearCount
-
evictCount
-
gcCount
-
idleCount
-
ttlCount
-
lruCount
-
name
-
shortName
-
maxSize
protected final int maxSize -
trimFrequency
protected final int trimFrequency -
maxIdleSecs
protected final int maxIdleSecs -
maxSecsToLive
protected final int maxSecsToLive -
trimOnPut
protected final long trimOnPut -
lock
-
mutationCounter
-
-
Constructor Details
-
DefaultServerCache
-
-
Method Details
-
periodicTrim
-
visit
- Specified by:
visitin interfaceServerCache
-
statistics
- Specified by:
statisticsin interfaceServerCache
-
getHitCount
public long getHitCount()Return the count of get hits. -
getMissCount
public long getMissCount()Return the count of get misses. -
hitRatio
public int hitRatio()- Specified by:
hitRatioin interfaceServerCache
-
getName
Return the name of the cache. -
getShortName
-
clear
public void clear()Clear the cache.- Specified by:
clearin interfaceServerCache
-
get
Return a value from the cache.- Specified by:
getin interfaceServerCache
-
unwrapEntry
Unwrap the cache entry - override for query cache to unwrap to the query result. -
getCacheEntry
Get the cache entry - override for query cache to validate dependent tables. -
putAll
- Specified by:
putAllin interfaceServerCache
-
put
Put a value into the cache.- Specified by:
putin interfaceServerCache
-
remove
Remove an entry from the cache.- Specified by:
removein interfaceServerCache
-
size
public int size()Return the number of elements in the cache.- Specified by:
sizein interfaceServerCache
-
getTrimSize
protected int getTrimSize()Return the size to trim to based on the max size.This returns 90% of the max size.
-
runEviction
public void runEviction()Run the eviction based on Idle time, Time to live and LRU last access.
-