Class DefaultServerCache

java.lang.Object
io.ebeaninternal.server.cache.DefaultServerCache
All Implemented Interfaces:
io.ebean.cache.ServerCache
Direct Known Subclasses:
DefaultServerQueryCache

public class DefaultServerCache extends Object implements io.ebean.cache.ServerCache
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.

  • Field Details

    • logger

      protected static final System.Logger logger
    • BY_LAST_ACCESS

      public static final DefaultServerCache.CompareByLastAccess 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

      protected final String name
    • shortName

      protected final String 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

      protected final ReentrantLock lock
    • mutationCounter

      protected final AtomicLong mutationCounter
  • Constructor Details

  • Method Details

    • periodicTrim

      public void periodicTrim(io.ebean.BackgroundExecutor executor)
    • visit

      public void visit(io.ebean.meta.MetricVisitor visitor)
      Specified by:
      visit in interface io.ebean.cache.ServerCache
    • statistics

      public io.ebean.cache.ServerCacheStatistics statistics(boolean reset)
      Specified by:
      statistics in interface io.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:
      hitRatio in interface io.ebean.cache.ServerCache
    • getName

      public String getName()
      Return the name of the cache.
    • getShortName

      public String getShortName()
    • clear

      public void clear()
      Clear the cache.
      Specified by:
      clear in interface io.ebean.cache.ServerCache
    • get

      public Object get(Object key)
      Return a value from the cache.
      Specified by:
      get in interface io.ebean.cache.ServerCache
    • unwrapEntry

      protected Object unwrapEntry(DefaultServerCache.CacheEntry entry)
      Unwrap the cache entry - override for query cache to unwrap to the query result.
    • getCacheEntry

      protected DefaultServerCache.CacheEntry getCacheEntry(Object key)
      Get the cache entry - override for query cache to validate dependent tables.
    • putAll

      public void putAll(Map<Object,Object> keyValues)
      Specified by:
      putAll in interface io.ebean.cache.ServerCache
    • put

      public void put(Object key, Object value)
      Put a value into the cache.
      Specified by:
      put in interface io.ebean.cache.ServerCache
    • remove

      public void remove(Object key)
      Remove an entry from the cache.
      Specified by:
      remove in interface io.ebean.cache.ServerCache
    • size

      public int size()
      Return the number of elements in the cache.
      Specified by:
      size in interface io.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.