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 ClassesModifier and TypeClassDescriptionprotected classprotected static interfaceprotected static classNested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener, org.eclipse.jetty.util.component.AbstractLifeCycle.StopExceptionNested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container
org.eclipse.jetty.util.component.Container.InheritedListener, org.eclipse.jetty.util.component.Container.ListenerNested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
org.eclipse.jetty.util.component.Dumpable.DumpableContainer, org.eclipse.jetty.util.component.Dumpable.DumpAppendableNested 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, STOPPINGFields inherited from interface org.eclipse.jetty.util.component.Dumpable
LEGEND -
Constructor Summary
ConstructorsConstructorDescriptionCachingHttpContentFactory(HttpContent.Factory authority, org.eclipse.jetty.io.ByteBufferPool.Sized bufferPool) -
Method Summary
Modifier and TypeMethodDescriptionvoidgetCache()intlonggetContent(String path) Get theHttpContentinstance of a path.intGet the max number of cached files.intlongprotected booleanisCacheable(HttpContent httpContent) Tests whether the given HttpContent is cacheable, and if there is enough room to fit it in the cache.newCachedContent(String p, HttpContent httpContent) protected voidvoidsetMaxCachedFiles(int maxCachedFiles) Set the max number of cached files.voidsetMaxCachedFileSize(int maxCachedFileSize) voidsetMaxCacheSize(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, updateBeansMethods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, setEventListeners, start, stop, toStringMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.eclipse.jetty.util.component.Container
getCachedBeans, getEventListenersMethods inherited from interface org.eclipse.jetty.util.component.Dumpable
dumpSelfMethods 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
-
flushCache
public void flushCache() -
isCacheable
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
Description copied from interface:HttpContent.FactoryGet theHttpContentinstance of a path.- Specified by:
getContentin interfaceHttpContent.Factory- Parameters:
path- The path.- Returns:
- A
HttpContentinstance. - Throws:
IOException- if unable to get content
-
newCachedContent
protected CachingHttpContentFactory.CachingHttpContent newCachedContent(String p, HttpContent httpContent) -
newNotFoundContent
-