Class DefaultServerCache

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

public class DefaultServerCache extends Object implements 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

  • Constructor Details

  • Method Details

    • periodicTrim

      public void periodicTrim(BackgroundExecutor executor)
    • visit

      public void visit(MetricVisitor visitor)
      Specified by:
      visit in interface ServerCache
    • statistics

      public ServerCacheStatistics statistics(boolean reset)
      Specified by:
      statistics in interface 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 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 ServerCache
    • get

      public Object get(Object key)
      Return a value from the cache.
      Specified by:
      get in interface 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 ServerCache
    • put

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

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

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