Class CachingHttpContentFactory

java.lang.Object
org.eclipse.jetty.http.content.CachingHttpContentFactory
All Implemented Interfaces:
HttpContent.Factory
Direct Known Subclasses:
ValidatingCachingHttpContentFactory

public class CachingHttpContentFactory extends Object implements HttpContent.Factory

HttpContent.Factory implementation that wraps any other HttpContent.Factory instance using it as a caching authority. Only HttpContent instances whose path is not a directory are cached.

No eviction is done by this HttpContent.Factory, once an entry is in the cache it is always assumed to be valid. This class can be extended to implement the validation behaviours on CachingHttpContentFactory.CachingHttpContent which allow entries to be evicted once they become invalid.


The default values for the cache are:
  • maxCachedFileSize: 268435456L
  • maxCachedFiles: 2048
  • maxCacheSize: 268435456L
See Also:
  • Constructor Details

  • Method Details

    • getCache

    • getCachedSize

      public long getCachedSize()
    • getCachedFiles

      public int getCachedFiles()
    • getMaxCachedFileSize

      public int getMaxCachedFileSize()
    • setMaxCachedFileSize

      public void setMaxCachedFileSize(int maxCachedFileSize)
    • getMaxCacheSize

      public long getMaxCacheSize()
    • setMaxCacheSize

      public void setMaxCacheSize(long maxCacheSize)
    • getMaxCachedFiles

      public int getMaxCachedFiles()
      Get the max number of cached files..
      Returns:
      the max number of cached files.
    • setMaxCachedFiles

      public void setMaxCachedFiles(int maxCachedFiles)
      Set the max number of cached files..
      Parameters:
      maxCachedFiles - the max number of cached files.
    • isUseDirectByteBuffers

      public boolean isUseDirectByteBuffers()
    • setUseDirectByteBuffers

      public void setUseDirectByteBuffers(boolean useDirectByteBuffers)
    • removeFromCache

      protected void removeFromCache(CachingHttpContentFactory.CachingHttpContent content)
    • flushCache

      public void flushCache()
    • isCacheable

      protected boolean isCacheable(HttpContent httpContent)
      Tests whether the given HttpContent is cacheable, and if there is enough room to fit it in the cache.
      Parameters:
      httpContent - the HttpContent to test.
      Returns:
      whether the HttpContent is cacheable.
    • getContent

      public HttpContent getContent(String path) throws IOException
      Specified by:
      getContent in interface HttpContent.Factory
      Parameters:
      path - The path within the context to the resource
      Returns:
      A HttpContent
      Throws:
      IOException - if unable to get content
    • newCachedContent

      protected CachingHttpContentFactory.CachingHttpContent newCachedContent(String p, HttpContent httpContent)
    • newNotFoundContent

      protected CachingHttpContentFactory.CachingHttpContent newNotFoundContent(String p)