Interface ILRUCache<K,​V extends Closeable>

  • Type Parameters:
    K - the key
    V - the value
    All Known Implementing Classes:
    LRUCacheImpl

    public interface ILRUCache<K,​V extends Closeable>
    LRU cache ADT
    Author:
    bulldog
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      V get​(K key)
      Get a cached resource with specific key This call will increment the reference counter of the keyed resource.
      Collection<V> getValues()
      All values cached
      void put​(K key, V value)
      Put a keyed resource with default ttl into the cache This call will increment the reference counter of the keyed resource.
      void put​(K key, V value, long ttlInMilliSeconds)
      Put a keyed resource with specific ttl into the cache This call will increment the reference counter of the keyed resource.
      void release​(K key)
      Release the cached resource with specific key This call will decrement the reference counter of the keyed resource.
      V remove​(K key)
      Remove the resource with specific key from the cache and close it synchronously afterwards.
      void removeAll()
      Remove all cached resource from the cache and close them asynchronously afterwards.
      int size()
      The size of the cache, equals to current total number of cached resources.
    • Method Detail

      • put

        void put​(K key,
                 V value,
                 long ttlInMilliSeconds)
        Put a keyed resource with specific ttl into the cache This call will increment the reference counter of the keyed resource.
        Parameters:
        key - the key of the cached resource
        value - the to be cached resource
        ttlInMilliSeconds - time to live in milliseconds
      • put

        void put​(K key,
                 V value)
        Put a keyed resource with default ttl into the cache This call will increment the reference counter of the keyed resource.
        Parameters:
        key - the key of the cached resource
        value - the to be cached resource
      • get

        V get​(K key)
        Get a cached resource with specific key This call will increment the reference counter of the keyed resource.
        Parameters:
        key - the key of the cached resource
        Returns:
        cached resource if exists
      • release

        void release​(K key)
        Release the cached resource with specific key This call will decrement the reference counter of the keyed resource.
        Parameters:
        key - key of resource to release
      • remove

        V remove​(K key)
          throws IOException
        Remove the resource with specific key from the cache and close it synchronously afterwards.
        Parameters:
        key - the key of the cached resource
        Returns:
        the removed resource if exists
        Throws:
        IOException - exception thrown if there is any IO error
      • removeAll

        void removeAll()
                throws IOException
        Remove all cached resource from the cache and close them asynchronously afterwards.
        Throws:
        IOException - exception thrown if there is any IO error
      • size

        int size()
        The size of the cache, equals to current total number of cached resources.
        Returns:
        the size of the cache
      • getValues

        Collection<V> getValues()
        All values cached
        Returns:
        a collection