Class FileCache

    • Constructor Detail

      • FileCache

        public FileCache()
    • Method Detail

      • add

        public FileCache.CacheResult add​(HttpRequestPacket request,
                                         java.io.File cacheFile)
        Add a File resource to the cache. If a client comes with not the latest version of this resource - the FileCache will return it the latest resource version.
      • createJmxManagementObject

        protected java.lang.Object createJmxManagementObject()
      • getSecondsMaxAge

        public int getSecondsMaxAge()
        Returns:
        the maximum time, in seconds, a file may be cached.
      • setSecondsMaxAge

        public void setSecondsMaxAge​(int secondsMaxAge)
        Sets the maximum time, in seconds, a file may be cached.
        Parameters:
        secondsMaxAge - max age of a cached file, in seconds.
      • getMaxCacheEntries

        public int getMaxCacheEntries()
        Returns:
        the maximum number of files that may be cached.
      • setMaxCacheEntries

        public void setMaxCacheEntries​(int maxCacheEntries)
        Sets the maximum number of files that may be cached.
        Parameters:
        maxCacheEntries - the maximum number of files that may be cached.
      • getMinEntrySize

        public long getMinEntrySize()
        Returns:
        the minimum size, in bytes, a file must be in order to be cached in the heap cache.
      • setMinEntrySize

        public void setMinEntrySize​(long minEntrySize)
        The maximum size, in bytes, a file must be in order to be cached in the heap cache.
        Parameters:
        minEntrySize - the maximum size, in bytes, a file must be in order to be cached in the heap cache.
      • getMaxEntrySize

        public long getMaxEntrySize()
        Returns:
        the maximum size, in bytes, a resource may be before it can no longer be considered cacheable.
      • setMaxEntrySize

        public void setMaxEntrySize​(long maxEntrySize)
        The maximum size, in bytes, a resource may be before it can no longer be considered cacheable.
        Parameters:
        maxEntrySize - the maximum size, in bytes, a resource may be before it can no longer be considered cacheable.
      • getMaxLargeFileCacheSize

        public long getMaxLargeFileCacheSize()
        Returns:
        the maximum size of the memory mapped cache for large files.
      • setMaxLargeFileCacheSize

        public void setMaxLargeFileCacheSize​(long maxLargeFileCacheSize)
        Sets the maximum size, in bytes, of the memory mapped cache for large files.
        Parameters:
        maxLargeFileCacheSize - the maximum size, in bytes, of the memory mapped cache for large files.
      • getMaxSmallFileCacheSize

        public long getMaxSmallFileCacheSize()
        Returns:
        the maximum size, in bytes, of the heap cache for files below the water mark set by getMinEntrySize().
      • setMaxSmallFileCacheSize

        public void setMaxSmallFileCacheSize​(long maxSmallFileCacheSize)
        The maximum size, in bytes, of the heap cache for files below the water mark set by getMinEntrySize().
        Parameters:
        maxSmallFileCacheSize - the maximum size, in bytes, of the heap cache for files below the water mark set by getMinEntrySize().
      • isEnabled

        public boolean isEnabled()
        Returns:
        true if the FileCache is enabled, otherwise false
      • setEnabled

        public void setEnabled​(boolean enabled)
        Enables/disables the FileCache. By default, the FileCache is disabled.
        Parameters:
        enabled - true to enable the FileCache.
      • getCompressionConfig

        public CompressionConfig getCompressionConfig()
        Returns the FileCache compression configuration settings.
      • getCompressedFilesFolder

        public java.io.File getCompressedFilesFolder()
        Returns the folder to be used to store temporary compressed files.
      • setCompressedFilesFolder

        public void setCompressedFilesFolder​(java.io.File compressedFilesFolder)
        Sets the folder to be used to store temporary compressed files.
      • isFileSendEnabled

        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:

        • JVM OS is HP-UX
        • JVM OS is Linux, and the Oracle JVM in use is 1.6.0_17 or older

        Finally, if the connection between endpoints is secure, send file functionality will be disabled regardless of configuration.

        Returns:
        true if resources will be sent using FileChannel.transferTo(long, long, java.nio.channels.WritableByteChannel).
        Since:
        2.3.5
      • setFileSendEnabled

        public 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). If disabled, the more traditional byte[] copy will be used to send content.
        Parameters:
        fileSendEnabled - true to enable FileChannel.transferTo(long, long, java.nio.channels.WritableByteChannel) support.
        Since:
        2.3.5
      • compressFile

        protected void compressFile​(FileCacheEntry entry)
        Creates a temporary compressed representation of the given cache entry.
      • addHeapSize

        protected final long addHeapSize​(long size)
      • subHeapSize

        protected final long subHeapSize​(long size)
      • getHeapCacheSize

        public long getHeapCacheSize()
        Return the heap space used for cache
        Returns:
        heap size
      • addMappedMemorySize

        protected final long addMappedMemorySize​(long size)
      • subMappedMemorySize

        protected final long subMappedMemorySize​(long size)
      • getMappedCacheSize

        public long getMappedCacheSize()
        Return the size of Mapped memory used for caching
        Returns:
        Mapped memory size
      • notifyProbesEntryAdded

        protected static void notifyProbesEntryAdded​(FileCache fileCache,
                                                     FileCacheEntry entry)
        Notify registered FileCacheProbes about the "entry added" event.
        Parameters:
        fileCache - the FileCache event occurred on.
        entry - entry been added
      • notifyProbesEntryRemoved

        protected static void notifyProbesEntryRemoved​(FileCache fileCache,
                                                       FileCacheEntry entry)
        Notify registered FileCacheProbes about the "entry removed" event.
        Parameters:
        fileCache - the FileCache event occurred on.
        entry - entry been removed
      • notifyProbesEntryHit

        protected static void notifyProbesEntryHit​(FileCache fileCache,
                                                   FileCacheEntry entry)
        Notify registered FileCacheProbes about the "entry hit event.
        Parameters:
        fileCache - the FileCache event occurred on.
        entry - entry been hit.
      • notifyProbesEntryMissed

        protected static void notifyProbesEntryMissed​(FileCache fileCache,
                                                      HttpRequestPacket request)
        Notify registered FileCacheProbes about the "entry missed" event.
        Parameters:
        fileCache - the FileCache event occurred on.
        request - HTTP request.
      • notifyProbesError

        protected static void notifyProbesError​(FileCache fileCache,
                                                java.lang.Throwable error)
        Notify registered FileCacheProbes about the error.
        Parameters:
        fileCache - the FileCache event occurred on.
      • convertToLong

        protected static long convertToLong​(java.lang.String dateHeader)