Class DefaultServerCache
java.lang.Object
io.ebeaninternal.server.cache.DefaultServerCache
- All Implemented Interfaces:
io.ebean.cache.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 io.ebean.metric.CountMetricprotected final io.ebean.metric.CountMetricprotected final io.ebean.metric.CountMetricprotected final io.ebean.metric.CountMetricprotected final io.ebean.metric.CountMetricprotected final ReentrantLockprotected static final System.Loggerprotected final io.ebean.metric.CountMetricprotected final Map<Object, SoftReference<DefaultServerCache.CacheEntry>> The underlying map (ConcurrentHashMap or similar)protected final intprotected final intprotected final intprotected final io.ebean.metric.CountMetricprotected final AtomicLongprotected final Stringprotected final io.ebean.metric.CountMetricprotected final io.ebean.metric.CountMetricprotected final Stringprotected final intprotected final longprotected final io.ebean.metric.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(io.ebean.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.io.ebean.cache.ServerCacheStatisticsstatistics(boolean reset) protected ObjectUnwrap the cache entry - override for query cache to unwrap to the query result.voidvisit(io.ebean.meta.MetricVisitor visitor) Methods inherited from class 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
protected final io.ebean.metric.CountMetric hitCount -
missCount
protected final io.ebean.metric.CountMetric missCount -
putCount
protected final io.ebean.metric.CountMetric putCount -
removeCount
protected final io.ebean.metric.CountMetric removeCount -
clearCount
protected final io.ebean.metric.CountMetric clearCount -
evictCount
protected final io.ebean.metric.CountMetric evictCount -
gcCount
protected final io.ebean.metric.CountMetric gcCount -
idleCount
protected final io.ebean.metric.CountMetric idleCount -
ttlCount
protected final io.ebean.metric.CountMetric ttlCount -
lruCount
protected final io.ebean.metric.CountMetric 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
public void periodicTrim(io.ebean.BackgroundExecutor executor) -
visit
public void visit(io.ebean.meta.MetricVisitor visitor) - Specified by:
visitin interfaceio.ebean.cache.ServerCache
-
statistics
public io.ebean.cache.ServerCacheStatistics statistics(boolean reset) - Specified by:
statisticsin interfaceio.ebean.cache.ServerCache
-
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 interfaceio.ebean.cache.ServerCache
-
getName
Return the name of the cache. -
getShortName
-
clear
public void clear()Clear the cache.- Specified by:
clearin interfaceio.ebean.cache.ServerCache
-
get
-
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
-
put
-
remove
Remove an entry from the cache.- Specified by:
removein interfaceio.ebean.cache.ServerCache
-
size
public int size()Return the number of elements in the cache.- Specified by:
sizein interfaceio.ebean.cache.ServerCache
-
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.
-