package Zend_Cache
subpackage Zend_Cache_Backend
copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
license New BSD License
inherited_from \Zend_Cache_Backend

 Methods

PUBLIC METHOD FOR UNIT TESTING ONLY !

___expire(string $id) 

Force a cache record to expire

Parameters

$id

string

cache id

Constructor

__construct(array $options = array()
inherited_from \Zend_Cache_Backend::__construct()

Parameters

$options

array

associative array of options

Exceptions

\Zend_Cache_Exception

Constructor

__construct(array $options = array()
Inherited

Parameters

$options

array

Associative array of options

Clean some cache records

clean(string $mode = \Zend_Cache::CLEANING_MODE_ALL, array $tags = array()) : boolean

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

$mode

string

clean mode

$tags

array

array of tags

Returns

booleantrue if no problem

Return an associative array of capabilities (booleans) of the backend

getCapabilities() : array

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)
inherited_from \Zend_Cache_Backend_ExtendedInterface::getCapabilities()

Returns

arrayassociative of with capabilities

Return the filling percentage of the backend storage

getFillingPercentage() : integer
inherited_from \Zend_Cache_Backend_ExtendedInterface::getFillingPercentage()

Exceptions

\Zend_Cache_Exception

Returns

integerinteger between 0 and 100

Return an array of stored cache ids

getIds() : array
inherited_from \Zend_Cache_Backend_ExtendedInterface::getIds()

Returns

arrayarray of stored cache ids (string)

Return an array of stored cache ids which match any given tags

getIdsMatchingAnyTags(array $tags = array()) : array

In case of multiple tags, a logical AND is made between tags

inherited_from \Zend_Cache_Backend_ExtendedInterface::getIdsMatchingAnyTags()

Parameters

$tags

array

array of tags

Returns

arrayarray of any matching cache ids (string)

Return an array of stored cache ids which match given tags

getIdsMatchingTags(array $tags = array()) : array

In case of multiple tags, a logical AND is made between tags

inherited_from \Zend_Cache_Backend_ExtendedInterface::getIdsMatchingTags()

Parameters

$tags

array

array of tags

Returns

arrayarray of matching cache ids (string)

Return an array of stored cache ids which don't match given tags

getIdsNotMatchingTags(array $tags = array()) : array

In case of multiple tags, a logical OR is made between tags

inherited_from \Zend_Cache_Backend_ExtendedInterface::getIdsNotMatchingTags()

Parameters

$tags

array

array of tags

Returns

arrayarray of not matching cache ids (string)

Get the life time

getLifetime(integer $specificLifetime) : integer
Inherited

if $specificLifetime is not false, the given specific life time is used else, the global lifetime is used

Parameters

$specificLifetime

integer

Returns

integerCache life time

Return an array of metadatas for the given cache id

getMetadatas(string $id) : array

The array must include these keys :

  • expire : the expire timestamp
  • tags : a string array of tags
  • mtime : timestamp of last modification time
inherited_from \Zend_Cache_Backend_ExtendedInterface::getMetadatas()

Parameters

$id

string

cache id

Returns

arrayarray of metadatas (false if the cache id is not found)

Returns an option

getOption(string $name) : mixed
Inherited

Parameters

$name

string

Optional, the options name to return

Exceptions

\Zend_Cache_Exceptions

Returns

mixed

Return an array of stored tags

getTags() : array
inherited_from \Zend_Cache_Backend_ExtendedInterface::getTags()

Returns

arrayarray of stored tags (string)

Determine system TMP directory and detect if we have read access

getTmpDir() : string
Inherited

inspired from Zend_File_Transfer_Adapter_Abstract

Exceptions

\Zend_Cache_Exception if unable to determine directory

Returns

string

Return true if the automatic cleaning is available for the backend

isAutomaticCleaningAvailable() : boolean
Inherited

DEPRECATED : use getCapabilities() instead

deprecated

Returns

boolean

Test if a cache is available for the given id and (if yes) return it (false else)

load(string $id, boolean $doNotTestCacheValidity = false) : string | false

Parameters

$id

string

cache id

$doNotTestCacheValidity

boolean

if set to true, the cache validity won't be tested

Returns

stringfalsecached datas

Remove a cache record

remove(string $id) : boolean

Parameters

$id

string

cache id

Returns

booleantrue if no problem

Save some string datas into a cache record

save(string $data, string $id, array $tags = array(), boolean|integer $specificLifetime = false) : boolean

Note : $data is always "string" (serialization is done by the core not by the backend)

Parameters

$data

string

Datas to cache

$id

string

Cache id

$tags

array

Array of strings, the cache record will be tagged by each string entry

$specificLifetime

booleaninteger

If != false, set a specific lifetime for this cache record (null => infinite lifetime)

Returns

booleantrue if no problem

Set the cache_dir (particular case of setOption() method)

setCacheDir(string $value, boolean $trailingSeparator = true) : void

Parameters

$value

string

$trailingSeparator

boolean

If true, add a trailing separator is necessary

Exceptions

\Zend_Cache_Exception

Set the frontend directives

setDirectives(array $directives) : void
Inherited

Parameters

$directives

array

Assoc of directives

Exceptions

\Zend_Cache_Exception

Set an option

setOption(string $name, mixed $value) : void
Inherited

Parameters

$name

string

$value

mixed

Exceptions

\Zend_Cache_Exception

Test if a cache is available or not (for the given id)

test(string $id) : mixed

Parameters

$id

string

cache id

Returns

mixedfalse (a cache is not available) or "last modified" timestamp (int) of the available cache record

Give (if possible) an extra lifetime to the given cache id

touch(string $id, integer $extraLifetime) : boolean
inherited_from \Zend_Cache_Backend_ExtendedInterface::touch()

Parameters

$id

string

cache id

$extraLifetime

integer

Returns

booleantrue if ok

Clean some cache records (protected method used for recursive stuff)

_clean(string $dir, string $mode = \Zend_Cache::CLEANING_MODE_ALL, array $tags = array()) : boolean

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

$dir

string

Directory to clean

$mode

string

Clean mode

$tags

array

Array of tags

Exceptions

\Zend_Cache_Exception

Returns

booleanTrue if no problem

Clear the metadatas array

_cleanMetadatas() : void

Drop a metadata record

_delMetadatas(string $id) : boolean

Parameters

$id

string

Cache id

Returns

booleanTrue if no problem

Compute & return the expire time

_expireTime(integer $lifetime) : integer

Parameters

$lifetime

integer

Returns

integerexpire time (unix timestamp)

Make and return a file name (with path)

_file(string $id) : string

Parameters

$id

string

Cache id

Returns

stringFile name (with path)

Return the file content of the given file

_fileGetContents(string $file) : string

Parameters

$file

string

File complete path

Returns

stringFile content (or false if problem)

Transform a file name into cache id and return it

_fileNameToId(string $fileName) : string

Parameters

$fileName

string

File name

Returns

stringCache id

Put the given string into the given file

_filePutContents(string $file, string $string) : boolean

Parameters

$file

string

File complete path

$string

string

String to put in file

Returns

booleantrue if no problem

_get()

_get($dir, $mode, $tags = array()

Parameters

$dir

$mode

$tags

Get a metadatas record

_getMetadatas(string $id) : array | false

Parameters

$id

string

Cache id

Returns

arrayfalseAssociative array of metadatas

Make a control key with the string containing datas

_hash(string $data, string $controlType) : string

Parameters

$data

string

Data

$controlType

string

Type of control 'md5', 'crc32' or 'strlen'

Exceptions

\Zend_Cache_Exception

Returns

stringControl key

Transform a cache id into a file name and return it

_idToFileName(string $id) : string

Parameters

$id

string

Cache id

Returns

stringFile name

Verify if the given temporary directory is readable and writable

_isGoodTmpDir(string $dir) : boolean
Inherited

Parameters

$dir

string

temporary directory

Returns

booleantrue if the directory is ok

Check if the given filename is a metadatas one

_isMetadatasFile(string $fileName) : boolean

Parameters

$fileName

string

File name

Returns

booleanTrue if it's a metadatas one

Load metadatas from disk

_loadMetadatas(string $id) : array | false

Parameters

$id

string

Cache id

Returns

arrayfalseMetadatas associative array

Log a message at the WARN (4) priority.

_log(string $message, integer $priority = 4) : void
Inherited

Parameters

$message

string

$priority

integer

Make sure if we enable logging that the Zend_Log class is available.

_loggerSanity() : void
Inherited

Create a default log object if none is set.

Exceptions

\Zend_Cache_Exception

Make and return a file name (with path) for metadatas

_metadatasFile(string $id) : string

Parameters

$id

string

Cache id

Returns

stringMetadatas file name (with path)

Return the complete directory path of a filename (including hashedDirectoryStructure)

_path(string $id, boolean $parts = false) : string

Parameters

$id

string

Cache id

$parts

boolean

if true, returns array of directory parts instead of single string

Returns

stringComplete directory path

Make the directory strucuture for the given id

_recursiveMkdirAndChmod(string $id) : boolean

Parameters

$id

string

cache id

Returns

booleantrue

Remove a file

_remove(string $file) : boolean

If we can't remove the file (because of locks or any problem), we will touch the file to invalidate it

Parameters

$file

string

Complete file path

Returns

booleanTrue if ok

Save metadatas to disk

_saveMetadatas(string $id, array $metadatas) : boolean

Parameters

$id

string

Cache id

$metadatas

array

Associative array

Returns

booleanTrue if no problem

Set a metadatas record

_setMetadatas(string $id, array $metadatas, boolean $save = true) : boolean

Parameters

$id

string

Cache id

$metadatas

array

Associative array of metadatas

$save

boolean

optional pass false to disable saving to file

Returns

booleanTrue if no problem

Test if the given cache id is available (and still valid as a cache record)

_test(string $id, boolean $doNotTestCacheValidity) : boolean | mixed

Parameters

$id

string

Cache id

$doNotTestCacheValidity

boolean

If set to true, the cache validity won't be tested

Returns

booleanmixedfalse (a cache is not available) or "last modified" timestamp (int) of the available cache record

 Properties

 

Frontend or Core directives

$_directives : array

Default

array('lifetime' => 3600, 'logging' => false, 'logger' => null)

=====> (int) lifetime :

  • Cache lifetime (in seconds)
  • If null, the cache is valid forever

=====> (int) logging :

  • if set to true, a logging is activated throw Zend_Log
 

Array of metadatas (each item is an associative array)

$_metadatasArray : array

Default

array()
 

Available options

$_options : array

Default

array('cache_dir' => null, 'file_locking' => true, 'read_control' => true, 'read_control_type' => 'crc32', 'hashed_directory_level' => 0, 'hashed_directory_perm' => 448, 'file_name_prefix' => 'zend_cache', 'cache_file_perm' => 384, 'metadatas_array_max_size' => 100)

=====> (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 :

  • deprecated
  • Permissions for hashed directory structure

=====> (int) hashed_directory_perm :

  • Permissions 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 :

  • deprecated
  • Permissions for cache files

=====> (int) cache_file_perm :

  • Permissions 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)
inherited_from \Zend_Cache_Backend::_options
 

Available options

$_options : array

Default

array()