Class EhBlockingCache

java.lang.Object
org.mybatis.caches.ehcache.AbstractEhcacheCache
org.mybatis.caches.ehcache.EhBlockingCache
All Implemented Interfaces:
org.apache.ibatis.cache.Cache

public class EhBlockingCache extends AbstractEhcacheCache
Cache implementation that wraps Ehcache 2 with BlockingCache semantics.

BlockingCache acquires a per-key lock when a cache miss occurs so that only one thread computes the missing value while others block. This prevents cache-stampede on a cold or expired entry.

Author:
Iwao AVE!
  • Constructor Details

    • EhBlockingCache

      public EhBlockingCache(String id)
      Instantiates a new eh blocking cache.
      Parameters:
      id - the id
  • Method Details

    • removeObject

      public Object removeObject(Object key)
      Description copied from class: AbstractEhcacheCache
      Specified by:
      removeObject in interface org.apache.ibatis.cache.Cache
      Overrides:
      removeObject in class AbstractEhcacheCache
    • rebuildCacheWith

      protected void rebuildCacheWith(net.sf.ehcache.config.CacheConfiguration newConfig)
      Removes the existing cache from the CacheManager and registers a new one built from newConfig. Subclasses may override this method to apply additional decorators (e.g. BlockingCache).

      Re-wraps the rebuilt cache in a BlockingCache after replacing it.

      Overrides:
      rebuildCacheWith in class AbstractEhcacheCache
      Parameters:
      newConfig - the configuration to use for the replacement cache