Class BoundedCache<K,​V>


  • @ThreadSafe
    public final class BoundedCache<K,​V>
    extends Object
    A thread-safe cache implementation that returns the value for a specified key, retrieving it by either getting the stored value from the cache or using a supplied function to calculate that value and add it to the cache.

    When the cache is full, batch eviction of unspecified values will be performed, with a default evictionBatchSize of 10.

    The user can configure the maximum size of the cache, which is set to a default of 150.

    Keys must not be null, otherwise an error will be thrown. Null values are not cached.

    • Method Detail

      • get

        public V get​(K key)
        Get a value based on the key. The key must not be null, otherwise an error is thrown. If the value exists in the cache, it's returned. Otherwise, the value is calculated based on the supplied function builder(Function).
      • size

        public int size()
      • containsKey

        public boolean containsKey​(K key)