Class FileCache

  • All Implemented Interfaces:
    org.glassfish.grizzly.monitoring.MonitoringAware<FileCacheProbe>

    public class FileCache
    extends Object
    implements org.glassfish.grizzly.monitoring.MonitoringAware<FileCacheProbe>
    This class implements a file caching mechanism used to cache static resources.
    Author:
    Jeanfrancois Arcand, Scott Oaks
    • Field Detail

      • monitoringConfig

        protected final org.glassfish.grizzly.monitoring.DefaultMonitoringConfig<FileCacheProbe> monitoringConfig
        File cache probes
    • Constructor Detail

      • FileCache

        public FileCache()
    • Method Detail

      • initialize

        public void initialize​(org.glassfish.grizzly.utils.DelayedExecutor delayedExecutor)
      • add

        public FileCache.CacheResult add​(org.glassfish.grizzly.http.HttpRequestPacket request,
                                         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.
      • add

        protected FileCache.CacheResult add​(org.glassfish.grizzly.http.HttpRequestPacket request,
                                            File cacheFile,
                                            long lastModified)
        Add a resource to the cache.
      • get

        public FileCacheEntry get​(org.glassfish.grizzly.http.HttpRequestPacket request)
        Returns FileCacheEntry. If FileCacheEntry has been found - this method also sets correspondent HttpResponsePacket status code and reason phrase.
      • createJmxManagementObject

        protected 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 org.glassfish.grizzly.http.CompressionConfig getCompressionConfig()
        Returns the FileCache compression configuration settings.
      • getCompressedFilesFolder

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

        public void setCompressedFilesFolder​(File compressedFilesFolder)
        Sets the folder to be used to store temporary compressed files.
      • 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
      • getMonitoringConfig

        public org.glassfish.grizzly.monitoring.MonitoringConfig<FileCacheProbe> getMonitoringConfig()
        Specified by:
        getMonitoringConfig in interface org.glassfish.grizzly.monitoring.MonitoringAware<FileCacheProbe>
      • 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,
                                                      org.glassfish.grizzly.http.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,
                                                Throwable error)
        Notify registered FileCacheProbes about the error.
        Parameters:
        fileCache - the FileCache event occurred on.
      • convertToLong

        protected static long convertToLong​(String dateHeader)