Class CacheManager.CacheMap

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.util.Map<Cache.Key,​java.lang.Object>, Cache
    Enclosing class:
    CacheManager

    private static class CacheManager.CacheMap
    extends java.util.LinkedHashMap<Cache.Key,​java.lang.Object>
    implements Cache
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.util.AbstractMap

        java.util.AbstractMap.SimpleEntry<K extends java.lang.Object,​V extends java.lang.Object>, java.util.AbstractMap.SimpleImmutableEntry<K extends java.lang.Object,​V extends java.lang.Object>
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int maxSize  
      private long ttl  
    • Constructor Summary

      Constructors 
      Constructor Description
      CacheMap​(int maxSize, long ttl)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void clearOld()  
      <T> HttpResponse<T> get​(Cache.Key key, java.util.function.Supplier<HttpResponse<T>> fetcher)
      Returns the cached HttpResponse for a key or uses the Supplier to fetch the response
      <T> java.util.concurrent.CompletableFuture getAsync​(Cache.Key key, java.util.function.Supplier<java.util.concurrent.CompletableFuture<HttpResponse<T>>> fetcher)
      Returns the cached HttpResponse for a key or uses the Supplier to fetch the response
      protected boolean removeEldestEntry​(java.util.Map.Entry<Cache.Key,​java.lang.Object> eldest)  
      • Methods inherited from class java.util.LinkedHashMap

        clear, containsValue, entrySet, forEach, get, getOrDefault, keySet, replaceAll, values
      • Methods inherited from class java.util.HashMap

        clone, compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, size
      • Methods inherited from class java.util.AbstractMap

        equals, hashCode, toString
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Map

        compute, computeIfAbsent, computeIfPresent, containsKey, equals, hashCode, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, size
    • Field Detail

      • maxSize

        private final int maxSize
      • ttl

        private long ttl
    • Constructor Detail

      • CacheMap

        CacheMap​(int maxSize,
                 long ttl)
    • Method Detail

      • get

        public <T> HttpResponse<T> get​(Cache.Key key,
                                       java.util.function.Supplier<HttpResponse<T>> fetcher)
        Description copied from interface: Cache
        Returns the cached HttpResponse for a key or uses the Supplier to fetch the response
        Specified by:
        get in interface Cache
        Type Parameters:
        T - the type of response
        Parameters:
        key - the cache key
        fetcher - a function to execute the request and return the response. This response should be cached by the implementation
        Returns:
        the Http Response
      • getAsync

        public <T> java.util.concurrent.CompletableFuture getAsync​(Cache.Key key,
                                                                   java.util.function.Supplier<java.util.concurrent.CompletableFuture<HttpResponse<T>>> fetcher)
        Description copied from interface: Cache
        Returns the cached HttpResponse for a key or uses the Supplier to fetch the response
        Specified by:
        getAsync in interface Cache
        Type Parameters:
        T - the type of response
        Parameters:
        key - the cache key
        fetcher - a function to execute the request and return the response. This response should be cached by the implementation
        Returns:
        the CompletableFuture for the response
      • clearOld

        private void clearOld()
      • removeEldestEntry

        protected boolean removeEldestEntry​(java.util.Map.Entry<Cache.Key,​java.lang.Object> eldest)
        Overrides:
        removeEldestEntry in class java.util.LinkedHashMap<Cache.Key,​java.lang.Object>