Package org.eclipse.jetty.server
Class CachedContentFactory
- java.lang.Object
-
- org.eclipse.jetty.server.CachedContentFactory
-
- All Implemented Interfaces:
HttpContent.ContentFactory
public class CachedContentFactory extends java.lang.Object implements HttpContent.ContentFactory
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
CachedContentFactory.CachedHttpContent
MetaData associated with a context Resource.class
CachedContentFactory.CachedPrecompressedHttpContent
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.ConcurrentMap<java.lang.String,CachedContentFactory.CachedHttpContent>
_cache
private java.util.concurrent.atomic.AtomicInteger
_cachedFiles
private java.util.concurrent.atomic.AtomicInteger
_cachedSize
private boolean
_etags
private ResourceFactory
_factory
private int
_maxCachedFiles
private int
_maxCachedFileSize
private int
_maxCacheSize
private MimeTypes
_mimeTypes
private CachedContentFactory
_parent
private CompressedContentFormat[]
_precompressedFormats
private boolean
_useFileMappedBuffer
private static Logger
LOG
private static java.util.Map<CompressedContentFormat,CachedContentFactory.CachedPrecompressedHttpContent>
NO_PRECOMPRESSED
-
Constructor Summary
Constructors Constructor Description CachedContentFactory(CachedContentFactory parent, ResourceFactory factory, MimeTypes mimeTypes, boolean useFileMappedBuffer, boolean etags, CompressedContentFormat[] precompressedFormats)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
flushCache()
int
getCachedFiles()
int
getCachedSize()
HttpContent
getContent(java.lang.String pathInContext, int maxBufferSize)
Returns an entry from the cache, or creates a new one.protected java.nio.ByteBuffer
getDirectBuffer(Resource resource)
protected java.nio.ByteBuffer
getIndirectBuffer(Resource resource)
protected java.nio.ByteBuffer
getMappedBuffer(Resource resource)
int
getMaxCachedFiles()
int
getMaxCachedFileSize()
int
getMaxCacheSize()
protected boolean
isCacheable(Resource resource)
boolean
isUseFileMappedBuffer()
private HttpContent
load(java.lang.String pathInContext, Resource resource, int maxBufferSize)
HttpContent
lookup(java.lang.String pathInContext)
Deprecated.void
setMaxCachedFiles(int maxCachedFiles)
void
setMaxCachedFileSize(int maxCachedFileSize)
void
setMaxCacheSize(int maxCacheSize)
private void
shrinkCache()
java.lang.String
toString()
-
-
-
Field Detail
-
LOG
private static final Logger LOG
-
NO_PRECOMPRESSED
private static final java.util.Map<CompressedContentFormat,CachedContentFactory.CachedPrecompressedHttpContent> NO_PRECOMPRESSED
-
_cache
private final java.util.concurrent.ConcurrentMap<java.lang.String,CachedContentFactory.CachedHttpContent> _cache
-
_cachedSize
private final java.util.concurrent.atomic.AtomicInteger _cachedSize
-
_cachedFiles
private final java.util.concurrent.atomic.AtomicInteger _cachedFiles
-
_factory
private final ResourceFactory _factory
-
_parent
private final CachedContentFactory _parent
-
_mimeTypes
private final MimeTypes _mimeTypes
-
_etags
private final boolean _etags
-
_precompressedFormats
private final CompressedContentFormat[] _precompressedFormats
-
_useFileMappedBuffer
private final boolean _useFileMappedBuffer
-
_maxCachedFileSize
private int _maxCachedFileSize
-
_maxCachedFiles
private int _maxCachedFiles
-
_maxCacheSize
private int _maxCacheSize
-
-
Constructor Detail
-
CachedContentFactory
public CachedContentFactory(CachedContentFactory parent, ResourceFactory factory, MimeTypes mimeTypes, boolean useFileMappedBuffer, boolean etags, CompressedContentFormat[] precompressedFormats)
Constructor.- Parameters:
parent
- the parent resource cachefactory
- the resource factorymimeTypes
- Mimetype to use for meta datauseFileMappedBuffer
- true to file memory mapped buffersetags
- true to support etagsprecompressedFormats
- array of precompression formats to support
-
-
Method Detail
-
getCachedSize
public int getCachedSize()
-
getCachedFiles
public int getCachedFiles()
-
getMaxCachedFileSize
public int getMaxCachedFileSize()
-
setMaxCachedFileSize
public void setMaxCachedFileSize(int maxCachedFileSize)
-
getMaxCacheSize
public int getMaxCacheSize()
-
setMaxCacheSize
public void setMaxCacheSize(int maxCacheSize)
-
getMaxCachedFiles
public int getMaxCachedFiles()
- Returns:
- the max number of cached files.
-
setMaxCachedFiles
public void setMaxCachedFiles(int maxCachedFiles)
- Parameters:
maxCachedFiles
- the max number of cached files.
-
isUseFileMappedBuffer
public boolean isUseFileMappedBuffer()
-
flushCache
public void flushCache()
-
lookup
@Deprecated public HttpContent lookup(java.lang.String pathInContext) throws java.io.IOException
Deprecated.- Throws:
java.io.IOException
-
getContent
public HttpContent getContent(java.lang.String pathInContext, int maxBufferSize) throws java.io.IOException
Returns an entry from the cache, or creates a new one.
- Specified by:
getContent
in interfaceHttpContent.ContentFactory
- Parameters:
pathInContext
- The key into the cachemaxBufferSize
- The maximum buffer size allocated for this request. For cached content, a larger buffer may have previously been allocated and returned by theHttpContent.getDirectBuffer()
orHttpContent.getIndirectBuffer()
calls.- Returns:
- The entry matching
pathInContext
, or a new entry if no matching entry was found. If the content exists but is not cacheable, then aResourceHttpContent
instance is returned. If the resource does not exist, then null is returned. - Throws:
java.io.IOException
- if the resource cannot be retrieved
-
isCacheable
protected boolean isCacheable(Resource resource)
- Parameters:
resource
- the resource to test- Returns:
- whether the resource is cacheable. The default implementation tests the cache sizes.
-
load
private HttpContent load(java.lang.String pathInContext, Resource resource, int maxBufferSize)
-
shrinkCache
private void shrinkCache()
-
getIndirectBuffer
protected java.nio.ByteBuffer getIndirectBuffer(Resource resource)
-
getMappedBuffer
protected java.nio.ByteBuffer getMappedBuffer(Resource resource)
-
getDirectBuffer
protected java.nio.ByteBuffer getDirectBuffer(Resource resource)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-