public class FileCache extends Object implements MonitoringAware<FileCacheProbe>
Modifier and Type | Class and Description |
---|---|
static class |
FileCache.CacheResult |
static class |
FileCache.CacheType |
Modifier and Type | Field and Description |
---|---|
protected DefaultMonitoringConfig<FileCacheProbe> |
monitoringConfig
File cache probes
|
Constructor and Description |
---|
FileCache() |
Modifier and Type | Method and Description |
---|---|
FileCache.CacheResult |
add(HttpRequestPacket request,
File cacheFile)
Add a
File resource to the cache. |
protected FileCache.CacheResult |
add(HttpRequestPacket request,
File cacheFile,
long lastModified)
Add a resource to the cache.
|
FileCache.CacheResult |
add(HttpRequestPacket request,
long lastModified)
Add a resource to the cache.
|
protected long |
addHeapSize(long size) |
protected long |
addMappedMemorySize(long size) |
protected void |
compressFile(FileCacheEntry entry)
Creates a temporary compressed representation of the given cache entry.
|
protected static long |
convertToLong(String dateHeader) |
protected Object |
createJmxManagementObject() |
FileCacheEntry |
get(HttpRequestPacket request)
Returns
FileCacheEntry . |
File |
getCompressedFilesFolder()
Returns the folder to be used to store temporary compressed files.
|
CompressionConfig |
getCompressionConfig()
Returns the FileCache compression configuration settings.
|
long |
getHeapCacheSize()
Return the heap space used for cache
|
long |
getMappedCacheSize()
Return the size of Mapped memory used for caching
|
int |
getMaxCacheEntries() |
long |
getMaxEntrySize() |
long |
getMaxLargeFileCacheSize() |
long |
getMaxSmallFileCacheSize() |
long |
getMinEntrySize() |
MonitoringConfig<FileCacheProbe> |
getMonitoringConfig()
Return the object associated
MonitoringConfig . |
int |
getSecondsMaxAge() |
void |
initialize(DelayedExecutor delayedExecutor) |
boolean |
isEnabled() |
boolean |
isFileSendEnabled()
Returns
true if File resources may be be sent using
FileChannel.transferTo(long, long, java.nio.channels.WritableByteChannel) . |
protected static void |
notifyProbesEntryAdded(FileCache fileCache,
FileCacheEntry entry)
Notify registered
FileCacheProbe s about the "entry added" event. |
protected static void |
notifyProbesEntryHit(FileCache fileCache,
FileCacheEntry entry)
Notify registered
FileCacheProbe s about the "entry hit event. |
protected static void |
notifyProbesEntryMissed(FileCache fileCache,
HttpRequestPacket request)
Notify registered
FileCacheProbe s about the "entry missed" event. |
protected static void |
notifyProbesEntryRemoved(FileCache fileCache,
FileCacheEntry entry)
Notify registered
FileCacheProbe s about the "entry removed" event. |
protected static void |
notifyProbesError(FileCache fileCache,
Throwable error)
Notify registered
FileCacheProbe s about the error. |
protected void |
remove(FileCacheEntry entry) |
void |
setCompressedFilesFolder(File compressedFilesFolder)
Sets the folder to be used to store temporary compressed files.
|
void |
setEnabled(boolean enabled)
Enables/disables the
FileCache . |
void |
setFileSendEnabled(boolean fileSendEnabled)
Configure whether or send-file support will enabled which allows sending
File resources via FileChannel.transferTo(long, long, java.nio.channels.WritableByteChannel) . |
void |
setMaxCacheEntries(int maxCacheEntries)
Sets the maximum number of files that may be cached.
|
void |
setMaxEntrySize(long maxEntrySize)
The maximum size, in bytes, a resource may be before it can no
longer be considered cacheable.
|
void |
setMaxLargeFileCacheSize(long maxLargeFileCacheSize)
Sets the maximum size, in bytes, of the memory mapped cache for large
files.
|
void |
setMaxSmallFileCacheSize(long maxSmallFileCacheSize)
The maximum size, in bytes, of the heap cache for files below the
water mark set by
getMinEntrySize() . |
void |
setMinEntrySize(long minEntrySize)
The maximum size, in bytes, a file must be in order to be cached
in the heap cache.
|
void |
setSecondsMaxAge(int secondsMaxAge)
Sets the maximum time, in seconds, a file may be cached.
|
protected long |
subHeapSize(long size) |
protected long |
subMappedMemorySize(long size) |
protected final DefaultMonitoringConfig<FileCacheProbe> monitoringConfig
public void initialize(DelayedExecutor delayedExecutor)
public FileCache.CacheResult add(HttpRequestPacket request, long lastModified)
add(org.glassfish.grizzly.http.HttpRequestPacket, java.io.File)
this method adds a resource to a cache but is not able to send the
resource content to a client if client doesn't have the latest version
of this resource.public FileCache.CacheResult add(HttpRequestPacket request, File cacheFile)
protected FileCache.CacheResult add(HttpRequestPacket request, File cacheFile, long lastModified)
public FileCacheEntry get(HttpRequestPacket request)
FileCacheEntry
.
If FileCacheEntry
has been found - this method also sets
correspondent HttpResponsePacket
status code and reason phrase.protected void remove(FileCacheEntry entry)
protected Object createJmxManagementObject()
public int getSecondsMaxAge()
public void setSecondsMaxAge(int secondsMaxAge)
secondsMaxAge
- max age of a cached file, in seconds.public int getMaxCacheEntries()
public void setMaxCacheEntries(int maxCacheEntries)
maxCacheEntries
- the maximum number of files that may be cached.public long getMinEntrySize()
public void setMinEntrySize(long minEntrySize)
minEntrySize
- the maximum size, in bytes, a file must be in order
to be cached in the heap cache.public long getMaxEntrySize()
public void setMaxEntrySize(long maxEntrySize)
maxEntrySize
- the maximum size, in bytes, a resource may be before it can no
longer be considered cacheable.public long getMaxLargeFileCacheSize()
public void setMaxLargeFileCacheSize(long maxLargeFileCacheSize)
maxLargeFileCacheSize
- the maximum size, in bytes, of the memory
mapped cache for large files.public long getMaxSmallFileCacheSize()
getMinEntrySize()
.public void setMaxSmallFileCacheSize(long maxSmallFileCacheSize)
getMinEntrySize()
.maxSmallFileCacheSize
- the maximum size, in bytes, of the heap
cache for files below the water mark set by getMinEntrySize()
.public boolean isEnabled()
true
if the FileCache
is enabled,
otherwise false
public void setEnabled(boolean enabled)
enabled
- true
to enable the FileCache
.public CompressionConfig getCompressionConfig()
public File getCompressedFilesFolder()
public void setCompressedFilesFolder(File compressedFilesFolder)
public boolean isFileSendEnabled()
Returns true
if File resources may be be sent using
FileChannel.transferTo(long, long, java.nio.channels.WritableByteChannel)
.
By default, this property will be true, except in the following cases:
Finally, if the connection between endpoints is secure, send file functionality will be disabled regardless of configuration.
true
if resources will be sent using
FileChannel.transferTo(long, long, java.nio.channels.WritableByteChannel)
.public void setFileSendEnabled(boolean fileSendEnabled)
File
resources via FileChannel.transferTo(long, long, java.nio.channels.WritableByteChannel)
.
If disabled, the more traditional byte[] copy will be used to send content.fileSendEnabled
- true
to enable FileChannel.transferTo(long, long, java.nio.channels.WritableByteChannel)
support.protected void compressFile(FileCacheEntry entry)
protected final long addHeapSize(long size)
protected final long subHeapSize(long size)
public long getHeapCacheSize()
protected final long addMappedMemorySize(long size)
protected final long subMappedMemorySize(long size)
public long getMappedCacheSize()
public MonitoringConfig<FileCacheProbe> getMonitoringConfig()
MonitoringConfig
.getMonitoringConfig
in interface MonitoringAware<FileCacheProbe>
MonitoringConfig
.protected static void notifyProbesEntryAdded(FileCache fileCache, FileCacheEntry entry)
FileCacheProbe
s about the "entry added" event.fileCache
- the FileCache event occurred on.entry
- entry been addedprotected static void notifyProbesEntryRemoved(FileCache fileCache, FileCacheEntry entry)
FileCacheProbe
s about the "entry removed" event.fileCache
- the FileCache event occurred on.entry
- entry been removedprotected static void notifyProbesEntryHit(FileCache fileCache, FileCacheEntry entry)
FileCacheProbe
s about the "entry hit event.fileCache
- the FileCache event occurred on.entry
- entry been hit.protected static void notifyProbesEntryMissed(FileCache fileCache, HttpRequestPacket request)
FileCacheProbe
s about the "entry missed" event.fileCache
- the FileCache event occurred on.request
- HTTP request.protected static void notifyProbesError(FileCache fileCache, Throwable error)
FileCacheProbe
s about the error.fileCache
- the FileCache event occurred on.protected static long convertToLong(String dateHeader)
Copyright © 2015 Oracle Corporation. All rights reserved.