Class CmsVfsNameBasedDiskCache

java.lang.Object
org.opencms.cache.CmsVfsNameBasedDiskCache
Direct Known Subclasses:
CmsPdfCache, CmsPdfThumbnailCache

public class CmsVfsNameBasedDiskCache extends 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 Details

    • CmsVfsNameBasedDiskCache

      public CmsVfsNameBasedDiskCache(String basepath, 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 Details

    • getCacheContent

      public byte[] getCacheContent(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 String getCacheName(CmsResource resource, 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

      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(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(String rfsName, byte[] content) throws 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:
      IOException - in case of disk access errors