Inheritances
Files
Overview
FRAMES
NO FRAMES

Class Zend_Cache_Backend_File

Zend_Cache_Backend
|
Zend_Cache_Backend_File
Defined in line 40 of file Cache/Backend/File.php.
PackageZend_Cache
SubpackageZend_Cache_Backend
CopyrightCopyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
Licensehttp://framework.zend.com/license/new-bsd New BSD License

Summary

Instance fields
# $_metadatasArray Array of metadatas (each item is an associative array)
# $_options Available options
Instance methods
+ ___expire() PUBLIC METHOD FOR UNIT TESTING ONLY !
+ __construct() Constructor
# _clean() Clean some cache records (protected method used for recursive stuff)
# _cleanMetadatas() Clear the metadatas array
# _delMetadatas() Drop a metadata record
# _expireTime() Compute & return the expire time
# _file() Make and return a file name (with path)
# _fileGetContents() Return the file content of the given file
# _fileNameToId() Transform a file name into cache id and return it
# _filePutContents() Put the given string into the given file
# _get()
# _getMetadatas() Get a metadatas record
# _hash() Make a control key with the string containing datas
# _idToFileName() Transform a cache id into a file name and return it
# _isMetadatasFile() Check if the given filename is a metadatas one
# _loadMetadatas() Load metadatas from disk
# _metadatasFile() Make and return a file name (with path) for metadatas
# _path() Return the complete directory path of a filename (including hashedDirectoryStructure)
# _recursiveMkdirAndChmod() Make the directory strucuture for the given id
# _remove() Remove a file
# _saveMetadatas() Save metadatas to disk
# _setMetadatas() Set a metadatas record
# _test() Test if the given cache id is available (and still valid as a cache record)
+ clean() Clean some cache records
+ getCapabilities() Return an associative array of capabilities (booleans) of the backend
+ getFillingPercentage() Return the filling percentage of the backend storage
+ getIds() Return an array of stored cache ids
+ getIdsMatchingAnyTags() Return an array of stored cache ids which match any given tags
+ getIdsMatchingTags() Return an array of stored cache ids which match given tags
+ getIdsNotMatchingTags() Return an array of stored cache ids which don't match given tags
+ getMetadatas() Return an array of metadatas for the given cache id
+ getTags() Return an array of stored tags
+ load() Test if a cache is available for the given id and (if yes) return it (false else)
+ remove() Remove a cache record
+ save() Save some string datas into a cache record
+ setCacheDir() Set the cache_dir (particular case of setOption() method)
+ test() Test if a cache is available or not (for the given id)
+ touch() Give (if possible) an extra lifetime to the given cache id

Details

Instance fields

$_metadatasArray
protected $_metadatasArray = array()
Array of metadatas (each item is an associative array)
Var array
$_options
protected $_options = array( 'cache_dir' => null, 'file_locking' => true, 'read_control' => true, 'read_control_type' => 'crc32', 'hashed_directory_level' => 0, 'hashed_directory_umask' => 0700, 'file_name_prefix' => 'zend_cache', 'cache_file_umask' => 0600, 'metadatas_array_max_size' => 100 )
Available options

=====> (string) cache_dir :
- Directory where to put the cache files

=====> (boolean) file_locking :
- Enable / disable file_locking
- Can avoid cache corruption under bad circumstances but it doesn't work on multithread
webservers and on NFS filesystems for example

=====> (boolean) read_control :
- Enable / disable read control
- If enabled, a control key is embeded in cache file and this key is compared with the one
calculated after the reading.

=====> (string) read_control_type :
- Type of read control (only if read control is enabled). Available values are :
'md5' for a md5 hash control (best but slowest)
'crc32' for a crc32 hash control (lightly less safe but faster, better choice)
'adler32' for an adler32 hash control (excellent choice too, faster than crc32)
'strlen' for a length only test (fastest)

=====> (int) hashed_directory_level :
- Hashed directory level
- Set the hashed directory structure level. 0 means "no hashed directory
structure", 1 means "one level of directory", 2 means "two levels"...
This option can speed up the cache only when you have many thousands of
cache file. Only specific benchs can help you to choose the perfect value
for you. Maybe, 1 or 2 is a good start.

=====> (int) hashed_directory_umask :
- Umask for hashed directory structure

=====> (string) file_name_prefix :
- prefix for cache files
- be really carefull with this option because a too generic value in a system cache dir
(like /tmp) can cause disasters when cleaning the cache

=====> (int) cache_file_umask :
- Umask for cache files

=====> (int) metatadatas_array_max_size :
- max size for the metadatas array (don't change this value unless you
know what you are doing)
Var array available options

Instance methods

___expire()
public function ___expire( $id)
PUBLIC METHOD FOR UNIT TESTING ONLY !

Force a cache record to expire
Parameters
string $id cache id
__construct()
public function __construct( array $options = array())
Constructor
Parameters
array $options
Returns void
_clean()
protected function _clean( $dir
$mode = Zend_Cache::CLEANING_MODE_ALL
$tags = array()
)
Clean some cache records (protected method used for recursive stuff)

Available modes are :
Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used)
Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used)
Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags
($tags can be an array of strings or a single string)
Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => remove cache entries not {matching one of the given tags}
($tags can be an array of strings or a single string)
Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG => remove cache entries matching any given tags
($tags can be an array of strings or a single string)
Parameters
string $dir Directory to clean
string $mode Clean mode
array $tags Array of tags
Returns boolean True if no problem
_cleanMetadatas()
protected function _cleanMetadatas( )
Clear the metadatas array
Returns void
_delMetadatas()
protected function _delMetadatas( $id)
Drop a metadata record
Parameters
string $id Cache id
Returns boolean True if no problem
_expireTime()
protected function _expireTime( $lifetime)
Compute & return the expire time
Parameters
$lifetime
Returns int expire time (unix timestamp)
_file()
protected function _file( $id)
Make and return a file name (with path)
Parameters
string $id Cache id
Returns string File name (with path)
_fileGetContents()
protected function _fileGetContents( $file)
Return the file content of the given file
Parameters
string $file File complete path
Returns string File content (or false if problem)
_fileNameToId()
protected function _fileNameToId( $fileName)
Transform a file name into cache id and return it
Parameters
string $fileName File name
Returns string Cache id
_filePutContents()
protected function _filePutContents( $file
$string
)
Put the given string into the given file
Parameters
string $file File complete path
string $string String to put in file
Returns boolean true if no problem
_get()
protected function _get( $dir
$mode
$tags = array()
)
Parameters
$dir
$mode
$tags
_getMetadatas()
protected function _getMetadatas( $id)
Get a metadatas record
Parameters
string $id Cache id
Returns array|false Associative array of metadatas
_hash()
protected function _hash( $data
$controlType
)
Make a control key with the string containing datas
Parameters
string $data Data
string $controlType Type of control 'md5', 'crc32' or 'strlen'
Returns string Control key
_idToFileName()
protected function _idToFileName( $id)
Transform a cache id into a file name and return it
Parameters
string $id Cache id
Returns string File name
_isMetadatasFile()
protected function _isMetadatasFile( $fileName)
Check if the given filename is a metadatas one
Parameters
string $fileName File name
Returns boolean True if it's a metadatas one
_loadMetadatas()
protected function _loadMetadatas( $id)
Load metadatas from disk
Parameters
string $id Cache id
Returns array|false Metadatas associative array
_metadatasFile()
protected function _metadatasFile( $id)
Make and return a file name (with path) for metadatas
Parameters
string $id Cache id
Returns string Metadatas file name (with path)
_path()
protected function _path( $id
$parts = false
)
Return the complete directory path of a filename (including hashedDirectoryStructure)
Parameters
string $id Cache id
boolean $parts if true, returns array of directory parts instead of single string
Returns string Complete directory path
_recursiveMkdirAndChmod()
protected function _recursiveMkdirAndChmod( $id)
Make the directory strucuture for the given id
Parameters
string $id cache id
Returns boolean true
_remove()
protected function _remove( $file)
Remove a file

If we can't remove the file (because of locks or any problem), we will touch
the file to invalidate it
Parameters
string $file Complete file path
Returns boolean True if ok
_saveMetadatas()
protected function _saveMetadatas( $id
$metadatas
)
Save metadatas to disk
Parameters
string $id Cache id
array $metadatas Associative array
Returns boolean True if no problem
_setMetadatas()
protected function _setMetadatas( $id
$metadatas
$save = true
)
Set a metadatas record
Parameters
string $id Cache id
array $metadatas Associative array of metadatas
boolean $save optional pass false to disable saving to file
Returns boolean True if no problem
_test()
protected function _test( $id
$doNotTestCacheValidity
)
Test if the given cache id is available (and still valid as a cache record)
Parameters
string $id Cache id
boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
Returns boolean|mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record
clean()
public function clean( $mode = Zend_Cache::CLEANING_MODE_ALL
$tags = array()
)
Clean some cache records

Available modes are :
'all' (default) => remove all cache entries ($tags is not used)
'old' => remove too old cache entries ($tags is not used)
'matchingTag' => remove cache entries matching all given tags
($tags can be an array of strings or a single string)
'notMatchingTag' => remove cache entries not matching one of the given tags
($tags can be an array of strings or a single string)
'matchingAnyTag' => remove cache entries matching any given tags
($tags can be an array of strings or a single string)
Parameters
string $mode clean mode
tags array $tags array of tags
Returns boolean true if no problem
getCapabilities()
public function getCapabilities( )
Return an associative array of capabilities (booleans) of the backend

The array must include these keys :
- automatic_cleaning (is automating cleaning necessary)
- tags (are tags supported)
- expired_read (is it possible to read expired cache records
(for doNotTestCacheValidity option for example))
- priority does the backend deal with priority when saving
- infinite_lifetime (is infinite lifetime can work with this backend)
- get_list (is it possible to get the list of cache ids and the complete list of tags)
Returns array associative of with capabilities
getFillingPercentage()
public function getFillingPercentage( )
Return the filling percentage of the backend storage
Returns int integer between 0 and 100
getIds()
public function getIds( )
Return an array of stored cache ids
Returns array array of stored cache ids (string)
getIdsMatchingAnyTags()
public function getIdsMatchingAnyTags( $tags = array())
Return an array of stored cache ids which match any given tags

In case of multiple tags, a logical AND is made between tags
Parameters
array $tags array of tags
Returns array array of any matching cache ids (string)
getIdsMatchingTags()
public function getIdsMatchingTags( $tags = array())
Return an array of stored cache ids which match given tags

In case of multiple tags, a logical AND is made between tags
Parameters
array $tags array of tags
Returns array array of matching cache ids (string)
getIdsNotMatchingTags()
public function getIdsNotMatchingTags( $tags = array())
Return an array of stored cache ids which don't match given tags

In case of multiple tags, a logical OR is made between tags
Parameters
array $tags array of tags
Returns array array of not matching cache ids (string)
getMetadatas()
public function getMetadatas( $id)
Return an array of metadatas for the given cache id

The array must include these keys :
- expire : the expire timestamp
- tags : a string array of tags
- mtime : timestamp of last modification time
Parameters
string $id cache id
Returns array array of metadatas (false if the cache id is not found)
getTags()
public function getTags( )
Return an array of stored tags
Returns array array of stored tags (string)
load()
public function load( $id
$doNotTestCacheValidity = false
)
Test if a cache is available for the given id and (if yes) return it (false else)
Parameters
string $id cache id
boolean $doNotTestCacheValidity if set to true, the cache validity won't be tested
Returns string|false cached datas
remove()
public function remove( $id)
Remove a cache record
Parameters
string $id cache id
Returns boolean true if no problem
save()
public function save( $data
$id
$tags = array()
$specificLifetime = false
)
Save some string datas into a cache record

Note : $data is always "string" (serialization is done by the
core not by the backend)
Parameters
string $data Datas to cache
string $id Cache id
array $tags Array of strings, the cache record will be tagged by each string entry
int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
Returns boolean true if no problem
setCacheDir()
public function setCacheDir( $value
$trailingSeparator = true
)
Set the cache_dir (particular case of setOption() method)
Parameters
string $value
boolean $trailingSeparator If true, add a trailing separator is necessary
Returns void
test()
public function test( $id)
Test if a cache is available or not (for the given id)
Parameters
string $id cache id
Returns mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record
touch()
public function touch( $id
$extraLifetime
)
Give (if possible) an extra lifetime to the given cache id
Parameters
string $id cache id
int $extraLifetime
Returns boolean true if ok