Class BasicHttpCacheStorage

  • All Implemented Interfaces:
    HttpCacheStorage

    @Contract(threading=SAFE)
    public class BasicHttpCacheStorage
    extends java.lang.Object
    implements HttpCacheStorage
    Basic HttpCacheStorage implementation backed by an instance of LinkedHashMap. In other words, cache entries and the cached response bodies are held in-memory. This cache does NOT deallocate resources associated with the cache entries; it is intended for use with HeapResource and similar. This is the default cache storage backend used by CachingHttpClients.
    Since:
    4.1
    • Constructor Detail

      • BasicHttpCacheStorage

        public BasicHttpCacheStorage​(CacheConfig config)
    • Method Detail

      • putEntry

        public void putEntry​(java.lang.String url,
                             HttpCacheEntry entry)
                      throws java.io.IOException
        Places a HttpCacheEntry in the cache
        Specified by:
        putEntry in interface HttpCacheStorage
        Parameters:
        url - Url to use as the cache key
        entry - HttpCacheEntry to place in the cache
        Throws:
        java.io.IOException
      • getEntry

        public HttpCacheEntry getEntry​(java.lang.String url)
                                throws java.io.IOException
        Gets an entry from the cache, if it exists
        Specified by:
        getEntry in interface HttpCacheStorage
        Parameters:
        url - Url that is the cache key
        Returns:
        HttpCacheEntry if one exists, or null for cache miss
        Throws:
        java.io.IOException
      • removeEntry

        public void removeEntry​(java.lang.String url)
                         throws java.io.IOException
        Removes a HttpCacheEntry from the cache
        Specified by:
        removeEntry in interface HttpCacheStorage
        Parameters:
        url - Url that is the cache key
        Throws:
        java.io.IOException
      • updateEntry

        public void updateEntry​(java.lang.String url,
                                HttpCacheUpdateCallback callback)
                         throws java.io.IOException
        Description copied from interface: HttpCacheStorage
        Atomically applies the given callback to update an existing cache entry under a given key.
        Specified by:
        updateEntry in interface HttpCacheStorage
        Parameters:
        url - indicates which entry to modify
        callback - performs the update; see HttpCacheUpdateCallback for details, but roughly the callback expects to be handed the current entry and will return the new value for the entry.
        Throws:
        java.io.IOException