Zend Framework  1.12
Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
Zend_Cache_Core Class Reference

Public Member Functions

 __construct ($options=array())
 Constructor.
 
 setConfig (Zend_Config $config)
 Set options using an instance of type Zend_Config.
 
 setBackend (Zend_Cache_Backend $backendObject)
 Set the backend.
 
 getBackend ()
 Returns the backend.
 
 setOption ($name, $value)
 Public frontend to set an option.
 
 getOption ($name)
 Public frontend to get an option value.
 
 setLifetime ($newLifetime)
 Force a new lifetime.
 
 load ($id, $doNotTestCacheValidity=false, $doNotUnserialize=false)
 Test if a cache is available for the given id and (if yes) return it (false else)
 
 test ($id)
 Test if a cache is available for the given id.
 
 save ($data, $id=null, $tags=array(), $specificLifetime=false, $priority=8)
 Save some data in a cache.
 
 remove ($id)
 Remove a cache.
 
 clean ($mode= 'all', $tags=array())
 Clean cache entries.
 
 getIdsMatchingTags ($tags=array())
 Return an array of stored cache ids which match given tags.
 
 getIdsNotMatchingTags ($tags=array())
 Return an array of stored cache ids which don't match given tags.
 
 getIdsMatchingAnyTags ($tags=array())
 Return an array of stored cache ids which match any given tags.
 
 getIds ()
 Return an array of stored cache ids.
 
 getTags ()
 Return an array of stored tags.
 
 getFillingPercentage ()
 Return the filling percentage of the backend storage.
 
 getMetadatas ($id)
 Return an array of metadatas for the given cache id.
 
 touch ($id, $extraLifetime)
 Give (if possible) an extra lifetime to the given cache id.
 

Public Attributes

const BACKEND_NOT_SUPPORTS_TAG = 'tags are not supported by the current backend'
 Messages.
 
const BACKEND_NOT_IMPLEMENTS_EXTENDED_IF = 'Current backend doesn\'t implement the Zend_Cache_Backend_ExtendedInterface, so this method is not available'
 

Protected Member Functions

 _loggerSanity ()
 Make sure if we enable logging that the Zend_Log class is available.
 
 _log ($message, $priority=4)
 Log a message at the WARN (4) priority.
 
 _id ($id)
 Make and return a cache id.
 

Static Protected Member Functions

static _validateIdOrTag ($string)
 Validate a cache id or a tag (security, reliable filenames, reserved prefixes...)
 
static _validateTagsArray ($tags)
 Validate a tags array (security, reliable filenames, reserved prefixes...)
 

Protected Attributes

 $_backend = null
 Backend Object.
 
 $_options
 
 $_specificOptions = array()
 Not used for the core, just a sort a hint to get a common setOption() method (for the core and for frontends)
 
 $_extendedBackend = false
 True if the backend implements Zend_Cache_Backend_ExtendedInterface.
 
 $_backendCapabilities = array()
 

Static Protected Attributes

static $_directivesList = array('lifetime', 'logging', 'logger')
 Array of options which have to be transfered to backend.
 

Constructor & Destructor Documentation

__construct (   $options = array())

Constructor.

Parameters
array | Zend_Config$optionsAssociative array of options or Zend_Config instance
Exceptions
Zend_Cache_Exception
Returns
void

Member Function Documentation

_id (   $id)
protected

Make and return a cache id.

Checks 'cache_id_prefix' and returns new id with prefix or simply the id if null

Parameters
string$idCache id
Returns
string Cache id (with or without prefix)
_log (   $message,
  $priority = 4 
)
protected

Log a message at the WARN (4) priority.

Parameters
string$message
Exceptions
Zend_Cache_Exception
Returns
void
_loggerSanity ( )
protected

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

Create a default log object if none is set.

Exceptions
Zend_Cache_Exception
Returns
void
static _validateIdOrTag (   $string)
staticprotected

Validate a cache id or a tag (security, reliable filenames, reserved prefixes...)

Throw an exception if a problem is found

Parameters
string$stringCache id or tag
Exceptions
Zend_Cache_Exception
Returns
void
static _validateTagsArray (   $tags)
staticprotected

Validate a tags array (security, reliable filenames, reserved prefixes...)

Throw an exception if a problem is found

Parameters
array$tagsArray of tags
Exceptions
Zend_Cache_Exception
Returns
void
clean (   $mode = 'all',
  $tags = array() 
)

Clean cache entries.

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
array | string$tags
Exceptions
Zend_Cache_Exception
Returns
boolean True if ok
getBackend ( )

Returns the backend.

Returns
Zend_Cache_Backend backend object
getFillingPercentage ( )

Return the filling percentage of the backend storage.

Returns
int integer between 0 and 100
getIds ( )

Return an array of stored cache ids.

Returns
array array of stored cache ids (string)
getIdsMatchingAnyTags (   $tags = array())

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

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

Parameters
array$tagsarray of tags
Returns
array array of matching any cache ids (string)
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$tagsarray of tags
Returns
array array of matching cache ids (string)
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$tagsarray of tags
Returns
array array of not matching cache ids (string)
getMetadatas (   $id)

Return an array of metadatas for the given cache id.

The array will include these keys :

  • expire : the expire timestamp
  • tags : a string array of tags
  • mtime : timestamp of last modification time
Parameters
string$idcache id
Returns
array array of metadatas (false if the cache id is not found)
getOption (   $name)

Public frontend to get an option value.

Parameters
string$nameName of the option
Exceptions
Zend_Cache_Exception
Returns
mixed option value
getTags ( )

Return an array of stored tags.

Returns
array array of stored tags (string)
load (   $id,
  $doNotTestCacheValidity = false,
  $doNotUnserialize = false 
)

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

Parameters
string$idCache id
boolean$doNotTestCacheValidityIf set to true, the cache validity won't be tested
boolean$doNotUnserializeDo not serialize (even if automatic_serialization is true) => for internal use
Returns
mixed|false Cached datas
remove (   $id)

Remove a cache.

Parameters
string$idCache id to remove
Returns
boolean True if ok
save (   $data,
  $id = null,
  $tags = array(),
  $specificLifetime = false,
  $priority = 8 
)

Save some data in a cache.

Parameters
mixed$dataData to put in cache (can be another type than string if automatic_serialization is on)
string$idCache id (if not set, the last cache id will be used)
array$tagsCache tags
int$specificLifetimeIf != false, set a specific lifetime for this cache record (null => infinite lifetime)
int$priorityinteger between 0 (very low priority) and 10 (maximum priority) used by some particular backends
Exceptions
Zend_Cache_Exception
Returns
boolean True if no problem
setBackend ( Zend_Cache_Backend  $backendObject)

Set the backend.

Parameters
Zend_Cache_Backend$backendObject
Exceptions
Zend_Cache_Exception
Returns
void
setConfig ( Zend_Config  $config)

Set options using an instance of type Zend_Config.

Parameters
Zend_Config$config
Returns
Zend_Cache_Core
setLifetime (   $newLifetime)

Force a new lifetime.

The new value is set for the core/frontend but for the backend too (directive)

Parameters
int$newLifetimeNew lifetime (in seconds)
Returns
void
setOption (   $name,
  $value 
)

Public frontend to set an option.

There is an additional validation (relatively to the protected _setOption method)

Parameters
string$nameName of the option
mixed$valueValue of the option
Exceptions
Zend_Cache_Exception
Returns
void
test (   $id)

Test if a cache is available for the given id.

Parameters
string$idCache id
Returns
int|false Last modified time of cache entry if it is available, false otherwise
touch (   $id,
  $extraLifetime 
)

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

Parameters
string$idcache id
int$extraLifetime
Returns
boolean true if ok

Member Data Documentation

Zend_Cache_Backend_Interface $_backend = null
protected

Backend Object.

$_backendCapabilities = array()
protected
array $_directivesList = array('lifetime', 'logging', 'logger')
staticprotected

Array of options which have to be transfered to backend.

boolean $_extendedBackend = false
protected

True if the backend implements Zend_Cache_Backend_ExtendedInterface.

$_options
protected
Initial value:
= array(
'write_control' => true,
'caching' => true,
'cache_id_prefix' => null,
'automatic_serialization' => false,
'automatic_cleaning_factor' => 10,
'lifetime' => 3600,
'logging' => false,
'logger' => null,
'ignore_user_abort' => false
)
array $_specificOptions = array()
protected

Not used for the core, just a sort a hint to get a common setOption() method (for the core and for frontends)

const BACKEND_NOT_IMPLEMENTS_EXTENDED_IF = 'Current backend doesn\'t implement the Zend_Cache_Backend_ExtendedInterface, so this method is not available'
const BACKEND_NOT_SUPPORTS_TAG = 'tags are not supported by the current backend'

Messages.