Provides a file level storage system for the cache controller. Requires that the filesystem support file creation and modification times.
This writer supports building folder trees of cache data based on the cacheId specified. The folder path can be as deep as you like, however it is dependent on having sufficient key space in the cacheId. Sub-folders should improve I/O performance as it splits lots of small files into more manageable chunks.
The depth and length are configurable, however the same settings should be used to retrieve the cached object.
The cacheId is used as the file name and to build the folder structure when UseSubFolders is true. The full cacheID is still used as the final file cache name (this differs from earlier revisions of the cacheWriterFile class).
// UseSubFolders = false; $cacheId = 'MyCachedObject'; $fileName = FILESTORE/MyCachedObject.cache; // UseSubFolders = true, & FolderDepth = 4 $cacheId = 'MyCachedObject'; $fileName = FILESTORE/M/y/C/a/MyCachedObject.cache;
Some examples of using the file writer storage backend:
// store an item using defaults
$oWriter = new cacheWriterFile();
$oWriter->setCacheId('MyCachedObject');
$oWriter->setData(new stdClass());
$oWriter->save();
// check if cached and fetch the previous item
$oWriter = new cacheWriterFile();
$oWriter->setCacheId('MyCachedObject');
if ( $oWriter->isCached() ) {
$oWriter->load();
$oWriter->getData();
//...
}
// clear the cache
$oWriter = new cacheWriterFile();
$oWriter->setCacheId('MyCachedObject');
$oWriter->delete();
if ( $oWriter->isCached() ) {
// this should not execute...
}
public __construct([$inFileStore = null], [$inCacheId = null])
Returns a new file writer for the cache controller
public static clearCache($inFileStore, [$inExtension = 'cache'], [$inRecurse = true])
Removes all cache files in $inFileStore folder, recursing if set, returns the number of files removed
public runGc()
Runs garbage collection of the current cache folder, will recurse if their are additional folders
public checkFileStoreLocation()
Checks that the file store exists and can be accessed / written to
public createFileStoreLocation()
Creates the cache file location if it does not exist
public getSubFolderPath()
Returns the sub-folder path
public getCacheFileName()
Returns the filename for the cached object
public getFileStore()
Returns $_FileStore
public setFileStore($inFileStore)
Set $_FileStore to $inFileStore
public getFileExtension()
Returns $_FileExtension
public setFileExtension($inFileExtension)
Set $_FileExtension to $inFileExtension
public getUseSubFolders()
Returns $_UseSubFolders
public setUseSubFolders($inUseSubFolders)
Set $_UseSubFolders to $inUseSubFolders
public getFolderDepth()
Returns $_FolderDepth
public setFolderDepth($inFolderDepth)
Set $_FolderDepth to $inFolderDepth
public getSubFolderLength()
Returns $_SubFolderLength
public setSubFolderLength($inSubFolderLength)
Set $_SubFolderLength to $inSubFolderLength
public getCacheFolderPermissionsMask()
Returns $_CacheFolderPermissionsMask
public setCacheFolderPermissionsMask($inCacheFolderPermissionsMask)
Set $_CacheFolderPermissionsMask to $inCacheFolderPermissionsMask
public getCacheFilePermissionsMask()
Returns $_CacheFilePermissionsMask
public setCacheFilePermissionsMask($inCacheFilePermissionsMask)
Set $_CacheFilePermissionsMask to $inCacheFilePermissionsMask
Posted by: Scorpio Documentor (Writer), in Cache on 19 Nov 2009 @ 20:30
Tags: cache, cachewriter, cachewriterfile,
This
work is licenced under a
Creative Commons Licence.