Class CmsVfsNameBasedDiskCache

  • Direct Known Subclasses:
    CmsPdfCache, CmsPdfThumbnailCache

    public class CmsVfsNameBasedDiskCache
    extends java.lang.Object
    Implements a name based RFS file based disk cache, that handles parameter based versions of VFS files.

    This RFS cache operates on file names, plus a hash code calculated from CmsResource.getDateLastModified(), CmsResource.getDateCreated() and CmsResource.getLength(). Optional parameters can be appended to this name, which will be added as a second hash code. This way a file can have multiple versions based on different parameters.

    This cache is usable for resources from the online AND the offline project at the same time, because any change to a resource will result in a changed hash code. This means a resource changed in the offline project will have a new hash code compared to the online project. If the resource is identical in the online and the offline project, the generated hash codes will be the same.

    Since:
    6.2.0
    • Constructor Summary

      Constructors 
      Constructor Description
      CmsVfsNameBasedDiskCache​(java.lang.String basepath, java.lang.String foldername)
      Creates a new disk cache.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      byte[] getCacheContent​(java.lang.String rfsName)
      Returns the content of the requested file in the disk cache, or null if the file is not found in the cache, or is found but outdated.
      java.lang.String getCacheName​(CmsResource resource, java.lang.String parameters)
      Returns the RFS name to use for caching the given VFS resource with parameters in the disk cache.
      java.lang.String getRepositoryPath()
      Returns the absolute path of the cache repository in the RFS.
      boolean hasCacheContent​(java.lang.String rfsName)
      Returns the the requested file is available within the cache.
      void saveCacheFile​(java.lang.String rfsName, byte[] content)
      Saves the given file content in the disk cache.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CmsVfsNameBasedDiskCache

        public CmsVfsNameBasedDiskCache​(java.lang.String basepath,
                                        java.lang.String foldername)
        Creates a new disk cache.

        Parameters:
        basepath - the base path for the cache in the RFS
        foldername - the folder name for this cache, to be used a sub-folder for the base folder
    • Method Detail

      • getCacheContent

        public byte[] getCacheContent​(java.lang.String rfsName)
        Returns the content of the requested file in the disk cache, or null if the file is not found in the cache, or is found but outdated.

        Parameters:
        rfsName - the file RFS name to look up in the cache
        Returns:
        the content of the requested file in the disk cache, or null
      • getCacheName

        public java.lang.String getCacheName​(CmsResource resource,
                                             java.lang.String parameters)
        Returns the RFS name to use for caching the given VFS resource with parameters in the disk cache.

        Parameters:
        resource - the VFS resource to generate the cache name for
        parameters - the parameters of the request to the VFS resource
        Returns:
        the RFS name to use for caching the given VFS resource with parameters
      • getRepositoryPath

        public java.lang.String getRepositoryPath()
        Returns the absolute path of the cache repository in the RFS.

        Returns:
        the absolute path of the cache repository in the RFS
      • hasCacheContent

        public boolean hasCacheContent​(java.lang.String rfsName)
        Returns the the requested file is available within the cache.

        Parameters:
        rfsName - the file name
        Returns:
        true if the file is available
      • saveCacheFile

        public void saveCacheFile​(java.lang.String rfsName,
                                  byte[] content)
                           throws java.io.IOException
        Saves the given file content in the disk cache.

        Parameters:
        rfsName - the RFS name of the file to save the content in
        content - the content of the file to save
        Throws:
        java.io.IOException - in case of disk access errors