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, Container, Destroyable, Dumpable, Dumpable.DumpableContainer, LifeCycle
- Direct Known Subclasses:
ValidatingCachingHttpContentFactory
@ManagedObject
public class CachingHttpContentFactory
extends 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 AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListener, AbstractLifeCycle.StopExceptionNested classes/interfaces inherited from interface Container
Container.InheritedListener, Container.ListenerNested classes/interfaces inherited from interface Dumpable
Dumpable.DumpableContainer, Dumpable.DumpAppendableNested classes/interfaces inherited from interface LifeCycle
LifeCycle.Listener -
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionCachingHttpContentFactory(HttpContent.Factory authority, 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 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 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 Container
getCachedBeans, getEventListenersMethods inherited from interface Dumpable.DumpableContainer
isDumpable
-
Constructor Details
-
CachingHttpContentFactory
-
-
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
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
-