org.opencms.cache
Class CmsVfsDiskCache

java.lang.Object
  extended by org.opencms.cache.CmsVfsDiskCache

public class CmsVfsDiskCache
extends java.lang.Object

Implements a RFS file based disk cache, that handles parameter based versions of VFS files, providing a cache for the "online" and another for the "offline" project.

Since:
6.2.0
Version:
$Revision: 1.8 $
Author:
Alexander Kandzior

Constructor Summary
CmsVfsDiskCache(java.lang.String basepath, java.lang.String foldername)
          Creates a new disk cache.
 
Method Summary
 byte[] getCacheContent(java.lang.String rfsName, long dateLastModified)
          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(boolean online, java.lang.String rootPath, 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.
 void saveCacheFile(java.lang.String rfsName, byte[] content, long dateLastModified)
          Saves the given file content in the disk cache.
static java.io.File saveFile(java.lang.String rfsName, byte[] content)
          Saves the given file content to a RFS file of the given name (full path).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CmsVfsDiskCache

public CmsVfsDiskCache(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 subfolder for the base folder
Method Detail

saveFile

public static java.io.File saveFile(java.lang.String rfsName,
                                    byte[] content)
                             throws java.io.IOException
Saves the given file content to a RFS file of the given name (full path).

If the required parent folders do not exists, they are also created.

Parameters:
rfsName - the RFS name of the file to save the content in
content - the content of the file to save
Returns:
a reference to the File that was saved
Throws:
java.io.IOException - in case of disk access errors

getCacheContent

public byte[] getCacheContent(java.lang.String rfsName,
                              long dateLastModified)
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
dateLastModified - the date of last modification for the cache
Returns:
the content of the requested file in the VFS disk cache, or null

getCacheName

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

Parameters:
online - if true, the online disk cache is used, the offline disk cache otherwise
rootPath - the VFS resource root path to get the RFS 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

saveCacheFile

public void saveCacheFile(java.lang.String rfsName,
                          byte[] content,
                          long dateLastModified)
                   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
dateLastModified - the date of last modification to set for the save file
Throws:
java.io.IOException - in case of disk access errors