Class CachingHttpContentFactory

java.lang.Object
org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.ContainerLifeCycle
org.eclipse.jetty.http.content.CachingHttpContentFactory
All Implemented Interfaces:
HttpContent.Factory, org.eclipse.jetty.util.component.Container, org.eclipse.jetty.util.component.Destroyable, org.eclipse.jetty.util.component.Dumpable, org.eclipse.jetty.util.component.Dumpable.DumpableContainer, org.eclipse.jetty.util.component.LifeCycle
Direct Known Subclasses:
ValidatingCachingHttpContentFactory

@ManagedObject public class CachingHttpContentFactory extends org.eclipse.jetty.util.component.ContainerLifeCycle 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 behaviors 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:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    protected class 
     
    protected static interface 
     
    protected static class 
     

    Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

    org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener, org.eclipse.jetty.util.component.AbstractLifeCycle.StopException

    Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container

    org.eclipse.jetty.util.component.Container.InheritedListener, org.eclipse.jetty.util.component.Container.Listener

    Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable

    org.eclipse.jetty.util.component.Dumpable.DumpableContainer, org.eclipse.jetty.util.component.Dumpable.DumpAppendable

    Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle

    org.eclipse.jetty.util.component.LifeCycle.Listener
  • Field Summary

    Fields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

    FAILED, STARTED, STARTING, STOPPED, STOPPING

    Fields inherited from interface org.eclipse.jetty.util.component.Dumpable

    LEGEND
  • Constructor Summary

    Constructors
    Constructor
    Description
    CachingHttpContentFactory(HttpContent.Factory authority, org.eclipse.jetty.io.ByteBufferPool.Sized bufferPool)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
     
    int
     
    long
     
    Get the HttpContent instance of a path.
    int
    Get the max number of cached files.
    int
     
    long
     
    protected boolean
    isCacheable(HttpContent httpContent)
    Tests whether the given HttpContent is cacheable, and if there is enough room to fit it in the cache.
     
     
    protected void
     
    void
    setMaxCachedFiles(int maxCachedFiles)
    Set the max number of cached files.
    void
    setMaxCachedFileSize(int maxCachedFileSize)
     
    void
    setMaxCacheSize(long maxCacheSize)
     

    Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle

    addBean, addBean, addEventListener, addManaged, addManaged, contains, destroy, doStart, doStop, dump, dump, dump, dumpObjects, dumpStdErr, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, installBean, installBean, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, start, stop, unmanage, updateBean, updateBean, updateBeans, updateBeans

    Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

    getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, setEventListeners, start, stop, toString

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.eclipse.jetty.util.component.Container

    getCachedBeans, getEventListeners

    Methods inherited from interface org.eclipse.jetty.util.component.Dumpable

    dumpSelf

    Methods inherited from interface org.eclipse.jetty.util.component.Dumpable.DumpableContainer

    isDumpable
  • Constructor Details

    • CachingHttpContentFactory

      public CachingHttpContentFactory(HttpContent.Factory authority, org.eclipse.jetty.io.ByteBufferPool.Sized bufferPool)
  • Method Details

    • getCache

    • getCachedSize

      @ManagedAttribute(value="Current total size in bytes of cached content", readonly=true) public long getCachedSize()
    • getCachedFiles

      @ManagedAttribute(value="Current number of cached files", readonly=true) public int getCachedFiles()
    • getMaxCachedFileSize

      @ManagedAttribute("Maximum size in bytes for a file to be eligible for caching") public int getMaxCachedFileSize()
    • setMaxCachedFileSize

      public void setMaxCachedFileSize(int maxCachedFileSize)
    • getMaxCacheSize

      @ManagedAttribute("Maximum total size in bytes allowed for the cache") public long getMaxCacheSize()
    • setMaxCacheSize

      public void setMaxCacheSize(long maxCacheSize)
    • getMaxCachedFiles

      @ManagedAttribute("Maximum number of entries allowed in the cache") 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.
    • 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
      Description copied from interface: HttpContent.Factory
      Get the HttpContent instance of a path.
      Specified by:
      getContent in interface HttpContent.Factory
      Parameters:
      path - The path.
      Returns:
      A HttpContent instance.
      Throws:
      IOException - if unable to get content
    • newCachedContent

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

      protected CachingHttpContentFactory.CachingHttpContent newNotFoundContent(String p)