core/xpdo/cache/xpdocachemanager.class.php

Show: inherited
Table of Contents

Classes implementing a default cache implementation for xPDO.

Package
xpdo  
Subpackage
cache  

\xPDOCache

Package: xpdo\cache

An abstract class that defines the methods a cache provider must implement.

Children
\xPDOWinCache
\xPDOMemCache
\xPDOAPCCache
\xPDOFileCache

Properties

Propertyprotected  $initialized= 'false'
Default valuefalseDetails
Type
n/a
Propertyprotected  $key= ''''
Default value''Details
Type
n/a
Propertyprotected  $options= 'array()'
Default valuearray()Details
Type
n/a
Propertypublic  $xpdo= 'null'
Default valuenullDetails
Type
n/a

Methods

methodpublic__construct(  $xpdo,  $options = array() ) : void

Parameters
Name Type Description
$xpdo
$options
methodpublicadd( string $key, string $var, integer $expire = 0, array $options = array() ) : boolean
abstract

Adds a value to the cache.

Parameters
Name Type Description
$key string

A unique key identifying the item being set.

$var string

A reference to the PHP variable representing the item.

$expire integer

The amount of seconds for the variable to expire in.

$options array

Additional options for the operation.

Returns
Type Description
boolean True if successful
Details
Access
public  
methodpublicdelete( string $key, array $options = array() ) : boolean
abstract

Deletes a value from the cache.

Parameters
Name Type Description
$key string

A unique key identifying the item being deleted.

$options array

Additional options for the operation.

Returns
Type Description
boolean True if successful
Details
Access
public  
methodpublicflush( array $options = array() ) : boolean
abstract

Flush all values from the cache.

Parameters
Name Type Description
$options array

Additional options for the operation.

Returns
Type Description
boolean True if successful.
Details
Access
public  
methodpublicget( string $key, array $options = array() ) : mixed

Gets a value from the cache.

Parameters
Name Type Description
$key string

A unique key identifying the item to fetch.

$options array

Additional options for the operation.

Returns
Type Description
mixed The value retrieved from the cache.
Details
Access
public  
methodpublicgetCacheKey( string $key, array $options = array() ) : string

Get the actual cache key the implementation will use.

Parameters
Name Type Description
$key string

The identifier the application uses.

$options array

Additional options for the operation.

Returns
Type Description
string The identifier with any implementation specific prefixes or other transformations applied.
methodpublicgetOption( string $key, array $options = array(), mixed $default = null ) : mixed

Get an option from supplied options, the cache options, or the xpdo config.

Parameters
Name Type Description
$key string

Unique identifier for the option.

$options array

A set of explicit options to override those from xPDO or the xPDOCache implementation.

$default mixed

An optional default value to return if no value is found.

Returns
Type Description
mixed The value of the option.
methodpublicisInitialized( ) : boolean

Indicates if this xPDOCache instance has been properly initialized.

Returns
Type Description
boolean true if the implementation was initialized successfully.
methodpublicreplace( string $key, string $var, integer $expire = 0, array $options = array() ) : boolean
abstract

Replaces a value in the cache.

Parameters
Name Type Description
$key string

A unique key identifying the item being set.

$var string

A reference to the PHP variable representing the item.

$expire integer

The amount of seconds for the variable to expire in.

$options array

Additional options for the operation.

Returns
Type Description
boolean True if successful
Details
Access
public  
methodpublicset( string $key, string $var, integer $expire = 0, array $options = array() ) : boolean
abstract

Sets a value in the cache.

Parameters
Name Type Description
$key string

A unique key identifying the item being set.

$var string

A reference to the PHP variable representing the item.

$expire integer

The amount of seconds for the variable to expire in.

$options array

Additional options for the operation.

Returns
Type Description
boolean True if successful
Details
Access
public  

\xPDOCacheManager

Package: xpdo\cache

The default cache manager implementation for xPDO.

Children
\modCacheManager

Constants

Constant  CACHE_PHP = 0
Constant  CACHE_JSON = 1
Constant  CACHE_SERIALIZE = 2
Constant  CACHE_DIR = 'objects/'
Constant  LOG_DIR = 'logs/'

Properties

Propertyprotected  $_umask= 'null'
Default valuenullDetails
Type
n/a
Propertyprotected  $caches= 'array()'
Default valuearray()Details
Type
n/a
Propertyprotected  $options= 'array()'
Default valuearray()Details
Type
n/a
Propertyprotected  $xpdo= 'null'
Default valuenullDetails
Type
n/a

Methods

methodpublic__construct(  $xpdo,  $options = array() ) : void

Parameters
Name Type Description
$xpdo
$options
methodpublicadd( string $key, mixed $var, integer $lifetime = 0, array $options = array() ) : void

Add a key-value pair to a cache provider if it does not already exist.

Parameters
Name Type Description
$key string

A unique key identifying the item being stored.

$var mixed

& $var A reference to the PHP variable representing the item.

$lifetime integer

Seconds the item will be valid in cache.

$options array

Additional options for the cache add operation.

methodpublicclean( array $options = array() ) : boolean

Flush the contents of a cache provider.

Parameters
Name Type Description
$options array

Additional options for the cache flush.

Returns
Type Description
boolean True if the flush was successful.
Details
Access
public  
methodpubliccopyFile( string $source, string $target, array $options = array() ) : boolean | array

Copies a file from a source file to a target directory.

Parameters
Name Type Description
$source string

The absolute path of the source file.

$target string

The absolute path of the target destination directory.

$options array

An array of options for this function.

Returns
Type Description
boolean | array Returns true if the copy operation was successful, or a single element array with filename as key and stat results of the successfully copied file as a result.
Details
Access
public  
methodpubliccopyTree( string $source, string $target, array $options = array() ) : array | boolean

Recursively copies a directory tree from a source directory to a target directory.

Parameters
Name Type Description
$source string

The absolute path of the source directory.

$target string

The absolute path of the target destination directory.

$options array

An array of options for this function.

Returns
Type Description
array | boolean Returns an array of all files and folders that were copied or false.
Details
Access
public  
methodpublicdelete( string $key, array $options = array() ) : boolean

Delete a key-value pair from a cache provider.

Parameters
Name Type Description
$key string

A unique key identifying the item being deleted.

$options array

Additional options for the cache deletion.

Returns
Type Description
boolean True if the deletion was successful.
Details
Access
public  
methodpublicdeleteTree( string $dirname, array $options = array('deleteTop' => false, 'skipDirs' => false, 'extensions' => array('.cache.php')) ) : boolean

Recursively deletes a directory tree of files.

Parameters
Name Type Description
$dirname string

An absolute path to the source directory to delete.

$options array

An array of options for this function.

Returns
Type Description
boolean Returns true if the deletion was successful.
Details
Access
public  
methodpublicendsWith( string $string, string | array $pattern ) : boolean

Sees if a string ends with a specific pattern or set of patterns.

Parameters
Name Type Description
$string string

The string to check.

$pattern string | array

The pattern or an array of patterns to check against.

Returns
Type Description
boolean True if the string ends with the pattern or any of the patterns provided.
Details
Access
public  
methodpublicescapeSingleQuotes( string $s ) : string

Escapes all single quotes in a string

Parameters
Name Type Description
$s string

The string to escape single quotes in.

Returns
Type Description
string The string with single quotes escaped.
Details
Access
public  
methodpublicgenerateObject( \xPDOObject $obj, string $objName, boolean $generateObjVars = false, boolean $generateRelated = false, string $objRef = 'this->xpdo', boolean $format = xPDOCacheManager::CACHE_PHP ) : string

Generate a PHP executable representation of an xPDOObject.

Parameters
Name Type Description
$obj \xPDOObject

An xPDOObject to generate the cache file for

$objName string

The name of the xPDOObject

$generateObjVars boolean

If true, will also generate maps for all object variables. Defaults to false.

$generateRelated boolean

If true, will also generate maps for all related objects. Defaults to false.

$objRef string

The reference to the xPDO instance, in string format.

$format boolean

The format to cache in. Defaults to xPDOCacheManager::CACHE_PHP, which is set to cache in executable PHP format.

Returns
Type Description
string The source map file, in string format.
Details
Access
public  
Todo
Complete $generateRelated functionality.  
Todo
Add stdObject support.  
methodpublicget( string $key, array $options = array() ) : mixed

Get a value from a cache provider by key.

Parameters
Name Type Description
$key string

A unique key identifying the item being retrieved.

$options array

Additional options for the cache retrieval.

Returns
Type Description
mixed The value of the object cache key
Details
Access
public  
methodpublicgetCachePath( ) : string

Get the absolute path to a writable directory for storing files.

Returns
Type Description
string The absolute path of the xPDO cache directory.
Details
Access
public  
methodpublicgetCacheProvider(  $key = '',  $options = array() ) : void

Get an instance of a provider which implements the xPDOCache interface.

Parameters
Name Type Description
$key
$options
methodpublicgetFilePermissions( ) : integer

Get default file permissions based on umask

Returns
Type Description
integer The default file permissions.
methodpublicgetFolderPermissions( ) : integer

Get default folder permissions based on umask

Returns
Type Description
integer The default folder permissions.
methodpublicgetOption( string $key, array $options = array(), mixed $default = null ) : mixed

Get an option from supplied options, the cacheManager options, or xpdo itself.

Parameters
Name Type Description
$key string

Unique identifier for the option.

$options array

A set of explicit options to override those from xPDO or the xPDOCacheManager implementation.

$default mixed

An optional default value to return if no value is found.

Returns
Type Description
mixed The value of the option.
methodpublicmatches( string $string, string | array $pattern ) : boolean

Sees if a string matches a specific pattern or set of patterns.

Parameters
Name Type Description
$string string

The string to check.

$pattern string | array

The pattern or an array of patterns to check against.

Returns
Type Description
boolean True if the string matched the pattern or any of the patterns provided.
Details
Access
public  
methodpublicrefresh( array $providers = array(), array $results = array() ) : array

Refresh specific or all cache providers.

The default behavior is to call clean() with the provided options

Parameters
Name Type Description
$providers array

An associative array with keys representing the cache provider key and the value an array of options.

$results array

&$results An associative array for collecting results for each provider.

Returns
Type Description
array An array of results for each provider that is refreshed.
methodpublicreplace( string $key, mixed $var, integer $lifetime = 0, array $options = array() ) : boolean

Replace a key-value pair in in a cache provider.

Parameters
Name Type Description
$key string

A unique key identifying the item being replaced.

$var mixed

& $var A reference to the PHP variable representing the item.

$lifetime integer

Seconds the item will be valid in objcache.

$options array

Additional options for the cache replace operation.

Returns
Type Description
boolean True if the replace was successful.
Details
Access
public  
methodpublicset( string $key, mixed $var, integer $lifetime = 0, array $options = array() ) : boolean

Set a key-value pair in a cache provider.

Parameters
Name Type Description
$key string

A unique key identifying the item being set.

$var mixed

& $var A reference to the PHP variable representing the item.

$lifetime integer

Seconds the item will be valid in objcache.

$options array

Additional options for the cache set operation.

Returns
Type Description
boolean True if the set was successful
Details
Access
public  
methodpublicwriteFile( string $filename, string $content, string $mode = 'wb', array $options = array() ) : boolean

Writes a file to the filesystem.

Parameters
Name Type Description
$filename string

The absolute path to the location the file will be written in.

$content string

The content of the newly written file.

$mode string

The php file mode to write in. Defaults to 'wb'. Note that this method always uses a (with b or t if specified) to open the file and that any mode except a means existing file contents will be overwritten.

$options array

An array of options for the function.

Returns
Type Description
boolean Returns true if the file was successfully written.
Details
Access
public  
methodpublicwriteTree( string $dirname, array $options = array() ) : boolean

Recursively writes a directory tree of files to the filesystem

Parameters
Name Type Description
$dirname string

The directory to write

$options array

An array of options for the function. Can also be a value representing a permissions mode to write new directories with, though this is deprecated.

Returns
Type Description
boolean Returns true if the directory was successfully written.
Details
Access
public  

\xPDOFileCache

Package: xpdo\cache

A simple file-based caching implementation using executable PHP.

This can be used to relieve database loads, though the overall performance is about the same as without the file-based cache. For maximum performance and scalability, use a server with memcached and the PHP memcache extension configured.

Parent(s)
\xPDOCache

Properties

Propertyprotected  $initialized= 'false'
inheritedInherited from: \xPDOCache::$$initialized
Default valuefalseDetails
Type
n/a
Inherited_from
\xPDOCache::$$initialized  
Propertyprotected  $key= ''''
inheritedInherited from: \xPDOCache::$$key
Default value''Details
Type
n/a
Inherited_from
\xPDOCache::$$key  
Propertyprotected  $options= 'array()'
inheritedInherited from: \xPDOCache::$$options
Default valuearray()Details
Type
n/a
Inherited_from
\xPDOCache::$$options  
Propertypublic  $xpdo= 'null'
inheritedInherited from: \xPDOCache::$$xpdo
Default valuenullDetails
Type
n/a
Inherited_from
\xPDOCache::$$xpdo  

Methods

methodpublic__construct(  $xpdo,  $options = array() ) : void

Parameters
Name Type Description
$xpdo
$options
methodpublicadd( string $key, string $var, integer $expire = 0, array $options = array() ) : boolean

Adds a value to the cache.

Parameters
Name Type Description
$key string

A unique key identifying the item being set.

$var string

A reference to the PHP variable representing the item.

$expire integer

The amount of seconds for the variable to expire in.

$options array

Additional options for the operation.

Returns
Type Description
boolean True if successful
methodpublicdelete( string $key, array $options = array() ) : boolean

Deletes a value from the cache.

Parameters
Name Type Description
$key string

A unique key identifying the item being deleted.

$options array

Additional options for the operation.

Returns
Type Description
boolean True if successful
methodpublicflush( array $options = array() ) : boolean

Flush all values from the cache.

Parameters
Name Type Description
$options array

Additional options for the operation.

Returns
Type Description
boolean True if successful.
methodpublicget( string $key, array $options = array() ) : mixed

Gets a value from the cache.

Parameters
Name Type Description
$key string

A unique key identifying the item to fetch.

$options array

Additional options for the operation.

Returns
Type Description
mixed The value retrieved from the cache.
methodpublicgetCacheKey( string $key, array $options = array() ) : string

Get the actual cache key the implementation will use.

Parameters
Name Type Description
$key string

The identifier the application uses.

$options array

Additional options for the operation.

Returns
Type Description
string The identifier with any implementation specific prefixes or other transformations applied.
methodpublicgetOption( string $key, array $options = array(), mixed $default = null ) : mixed
inherited

Get an option from supplied options, the cache options, or the xpdo config.

Inherited from: \xPDOCache::getOption()
Parameters
Name Type Description
$key string

Unique identifier for the option.

$options array

A set of explicit options to override those from xPDO or the xPDOCache implementation.

$default mixed

An optional default value to return if no value is found.

Returns
Type Description
mixed The value of the option.
methodpublicisInitialized( ) : boolean
inherited

Indicates if this xPDOCache instance has been properly initialized.

Inherited from: \xPDOCache::isInitialized()
Returns
Type Description
boolean true if the implementation was initialized successfully.
methodpublicreplace( string $key, string $var, integer $expire = 0, array $options = array() ) : boolean

Replaces a value in the cache.

Parameters
Name Type Description
$key string

A unique key identifying the item being set.

$var string

A reference to the PHP variable representing the item.

$expire integer

The amount of seconds for the variable to expire in.

$options array

Additional options for the operation.

Returns
Type Description
boolean True if successful
methodpublicset( string $key, string $var, integer $expire = 0, array $options = array() ) : boolean

Sets a value in the cache.

Parameters
Name Type Description
$key string

A unique key identifying the item being set.

$var string

A reference to the PHP variable representing the item.

$expire integer

The amount of seconds for the variable to expire in.

$options array

Additional options for the operation.

Returns
Type Description
boolean True if successful
Documentation was generated by DocBlox 0.18.1.