Class Cache<K,V>

java.lang.Object
com.booksaw.betterTeams.util.Cache<K,V>
Type Parameters:
K - The type of keys maintained by this cache
V - The type of values maintained by this cache

public class Cache<K,V> extends Object
A simple cache implementation with expiration and size-based eviction.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    A builder for creating Cache instances.
  • Method Summary

    Modifier and Type
    Method
    Description
    get(K key)
    Gets a value from the cache, loading it if necessary.
    void
    Removes an entry from the cache.
    void
    Removes all entries from the cache.
    int
    Returns the approximate number of entries in this cache.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • get

      public V get(K key)
      Gets a value from the cache, loading it if necessary.
      Parameters:
      key - the key to look up
      Returns:
      the value associated with the key
    • size

      public int size()
      Returns the approximate number of entries in this cache.
    • invalidateAll

      public void invalidateAll()
      Removes all entries from the cache.
    • invalidate

      public void invalidate(K key)
      Removes an entry from the cache.
      Parameters:
      key - the key to remove