public class CmsVfsNameBasedDiskCache extends java.lang.Object
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.
Constructor and Description |
---|
CmsVfsNameBasedDiskCache(java.lang.String basepath,
java.lang.String foldername)
Creates a new disk cache.
|
Modifier and Type | Method and 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.
|
public CmsVfsNameBasedDiskCache(java.lang.String basepath, java.lang.String foldername)
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 folderpublic byte[] getCacheContent(java.lang.String rfsName)
null
if the
file is not found in the cache, or is found but outdated.rfsName
- the file RFS name to look up in the cachenull
public java.lang.String getCacheName(CmsResource resource, java.lang.String parameters)
resource
- the VFS resource to generate the cache name forparameters
- the parameters of the request to the VFS resourcepublic java.lang.String getRepositoryPath()
public boolean hasCacheContent(java.lang.String rfsName)
rfsName
- the file nametrue
if the file is availablepublic void saveCacheFile(java.lang.String rfsName, byte[] content) throws java.io.IOException
rfsName
- the RFS name of the file to save the content incontent
- the content of the file to savejava.io.IOException
- in case of disk access errors