Class SimpleCache<K,​V>

  • Type Parameters:
    K - The class that the keys will be instances of.
    V - The class that the values will be instances of.

    public final class SimpleCache<K,​V>
    extends java.lang.Object
    A very basic cache with a timeout mechanism.
    • Constructor Summary

      Constructors 
      Constructor Description
      SimpleCache()
      Default Constructor
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      V get​(K key)
      Get an item from the cache.
      void put​(K key, V value)
      Add an item to the cache.
      void setTimeToLive​(int millis)
      Override the default cache timeout.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SimpleCache

        public SimpleCache()
        Default Constructor
    • Method Detail

      • setTimeToLive

        public void setTimeToLive​(int millis)
        Override the default cache timeout. Can be set at any time but only affects items cached after the value is set.
        Parameters:
        millis - The number of milliseconds until the cached item should be considered stale.
      • put

        public void put​(K key,
                        V value)
        Add an item to the cache.
        Parameters:
        key - The key of class K
        value - The value of class V
      • get

        public V get​(K key)
        Get an item from the cache.
        Parameters:
        key - The key of class K
        Returns:
        null if the item is not present or has expired, otherwise the value of class V