Package org.opencms.cache
Class CmsVfsNameBasedDiskCache
java.lang.Object
org.opencms.cache.CmsVfsNameBasedDiskCache
- Direct Known Subclasses:
CmsPdfCache
,CmsPdfThumbnailCache
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
ConstructorDescriptionCmsVfsNameBasedDiskCache
(String basepath, String foldername) Creates a new disk cache. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]
getCacheContent
(String rfsName) Returns the content of the requested file in the disk cache, ornull
if the file is not found in the cache, or is found but outdated.getCacheName
(CmsResource resource, String parameters) Returns the RFS name to use for caching the given VFS resource with parameters in the disk cache.Returns the absolute path of the cache repository in the RFS.boolean
hasCacheContent
(String rfsName) Returns the the requested file is available within the cache.void
saveCacheFile
(String rfsName, byte[] content) Saves the given file content in the disk cache.
-
Constructor Details
-
CmsVfsNameBasedDiskCache
Creates a new disk cache.- Parameters:
basepath
- the base path for the cache in the RFSfoldername
- the folder name for this cache, to be used a sub-folder for the base folder
-
-
Method Details
-
getCacheContent
Returns the content of the requested file in the disk cache, ornull
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
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 forparameters
- 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
Returns the the requested file is available within the cache.- Parameters:
rfsName
- the file name- Returns:
true
if the file is available
-
saveCacheFile
Saves the given file content in the disk cache.- Parameters:
rfsName
- the RFS name of the file to save the content incontent
- the content of the file to save- Throws:
IOException
- in case of disk access errors
-