java.lang.Object
com.maxmind.db.CHMCache
All Implemented Interfaces:
NodeCache

public class CHMCacheextends Object implements NodeCache
A simplistic cache using a ConcurrentHashMap. There's no eviction policy, it just fills up until reaching the specified capacity (or close enough at least, bounds check is not atomic :)
  • Field Details

    • DEFAULT_CAPACITY

      private static final int DEFAULT_CAPACITY
      Entries held when no capacity is given.
      See Also:
    • capacity

      private final int capacity
      Most entries the cache holds.
    • cache

      private final ConcurrentHashMap<Integer,Object> cache
      The cached values, by key.
    • cacheFull

      private boolean cacheFull
      True once the capacity has been reached.
  • Constructor Details

    • CHMCache

      public CHMCache()
      Create a cache with default capacity.
    • CHMCache

      public CHMCache(int capacity)
      Create a cache with the given capacity.
      Parameters:
      capacity - the maximum number of entries
  • Method Details

    • get

      public Object get(int key, NodeCache.Loader loader) throws IOException
      Description copied from interface: NodeCache
      Get a value from the cache, loading it if necessary.
      Specified by:
      get in interface NodeCache
      Parameters:
      key - the cache key
      loader - the loader to use if the key is not in cache
      Returns:
      the cached or loaded value
      Throws:
      IOException - if loading fails