core/model/modx/modcachemanager.class.php

Show: inherited
Table of Contents

Contains the xPDOCacheManager implementation for MODX.

Package
modx  

\modCacheManager

Package: modx

The default xPDOCacheManager instance for MODX.

Through this class, MODX provides several types of default, file-based caching to reduce load and dependencies on the database, including:

  • partial modResource caching, which stores the object properties, along with individual modElement cache items
  • full caching of modContext and modSystemSetting data
  • object-level caching
  • db query-level caching
  • optional JSON object caching for increased Ajax performance possibilities
Parent(s)
\xPDOCacheManager

Constants

Constant  CACHE_PHP = 0
inheritedInherited from: \xPDOCacheManager::CACHE_PHP
Inherited_from
\xPDOCacheManager::CACHE_PHP  
Constant  CACHE_JSON = 1
inheritedInherited from: \xPDOCacheManager::CACHE_JSON
Inherited_from
\xPDOCacheManager::CACHE_JSON  
Constant  CACHE_SERIALIZE = 2
inheritedInherited from: \xPDOCacheManager::CACHE_SERIALIZE
Constant  CACHE_DIR = 'objects/'
inheritedInherited from: \xPDOCacheManager::CACHE_DIR
Inherited_from
\xPDOCacheManager::CACHE_DIR  
Constant  LOG_DIR = 'logs/'
inheritedInherited from: \xPDOCacheManager::LOG_DIR
Inherited_from
\xPDOCacheManager::LOG_DIR  

Properties

Propertyprotected  $_umask= 'null'
inheritedInherited from: \xPDOCacheManager::$$_umask
Default valuenullDetails
Type
n/a
Inherited_from
\xPDOCacheManager::$$_umask  
Propertyprotected  $caches= 'array()'
inheritedInherited from: \xPDOCacheManager::$$caches
Default valuearray()Details
Type
n/a
Inherited_from
\xPDOCacheManager::$$caches  
Propertypublic\modX  $modx= 'null'

A reference to the modX instance
Default valuenullDetails
Type
\modX
Propertyprotected  $options= 'array()'
inheritedInherited from: \xPDOCacheManager::$$options
Default valuearray()Details
Type
n/a
Inherited_from
\xPDOCacheManager::$$options  
Propertyprotected  $xpdo= 'null'
inheritedInherited from: \xPDOCacheManager::$$xpdo
Default valuenullDetails
Type
n/a
Inherited_from
\xPDOCacheManager::$$xpdo  

Methods

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

Constructor for modCacheManager that overrides xPDOCacheManager constructor to assign modX reference

Parameters
Name Type Description
$xpdo \$xpdo

A reference to the xPDO/modX instance

$options array

An array of configuration options

methodpublicadd( string $key, mixed $var, integer $lifetime = 0, array $options = array() ) : void
inherited

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

Inherited from: \xPDOCacheManager::add()
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.

methodpublicautoPublish( array $options = array() ) : array

Check for and process Resources with pub_date or unpub_date set to now or in past.

Parameters
Name Type Description
$options array

An array of options for the process.

Returns
Type Description
array An array containing published and unpublished Resource counts.
Details
Todo
Implement Context-isolated auto-publishing.  
methodpublicclean( array $options = array() ) : boolean
inherited

Flush the contents of a cache provider.

Inherited from: \xPDOCacheManager::clean()
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  
methodpublicclearCache( array $paths = array(), array $options = array() ) : array

Clear part or all of the MODX cache.

Parameters
Name Type Description
$paths array

An optional array of paths, relative to the cache path, to be deleted.

$options array

An optional associative array of cache clearing options:

  • objects: an array of objects or paths to flush from the db object cache
  • extensions: an array of file extensions to match when deleting the cache directories
Returns
Type Description
array
Details
Deprecated
Use refresh()  
methodpubliccopyFile( string $source, string $target, array $options = array() ) : boolean | array
inherited

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

Inherited from: \xPDOCacheManager::copyFile()
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
inherited

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

Inherited from: \xPDOCacheManager::copyTree()
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
inherited

Delete a key-value pair from a cache provider.

Inherited from: \xPDOCacheManager::delete()
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
inherited

Recursively deletes a directory tree of files.

Inherited from: \xPDOCacheManager::deleteTree()
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
inherited

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

Inherited from: \xPDOCacheManager::endsWith()
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
inherited

Escapes all single quotes in a string

Inherited from: \xPDOCacheManager::escapeSingleQuotes()
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  
methodpublicgenerateActionMap( string $cacheKey, array $options = array() ) : array

Generates a cache file for the manager actions.

Parameters
Name Type Description
$cacheKey string

The key to use when caching the action map.

$options array

An array of options

Returns
Type Description
array An array representing the action map.
Details
Access
public  
methodpublicgenerateConfig( array $options = array() ) : array

Generates the system settings cache for a MODX site.

Parameters
Name Type Description
$options array

Options for system settings generation.

Returns
Type Description
array The generated system settings array.
methodpublicgenerateContext( string $key, array $options = array() ) : array

Generates a cache entry for a MODX site Context.

Context cache entries can override site configuration settings and are responsible for loading the various listings and maps in the modX class, including resourceMap, aliasMap, and eventMap. It can also be used to setup or transform any other modX properties.

Parameters
Name Type Description
$key string

The modContext key to be cached.

$options array

Options for context settings generation.

Returns
Type Description
array An array containing all the context variable values.
Details
Todo
Further refactor the generation of aliasMap and resourceMap so it uses less memory/file size.  
Used_by
\modContext::prepare()  
Used_by
\modContext_mysql::prepare()  
Used_by
\modContext_sqlsrv::prepare()  
methodpublicgenerateLexiconTopic( string $cacheKey, array $entries = array(), array $options = array() ) : array

Generates a lexicon topic cache file from a collection of entries

Parameters
Name Type Description
$cacheKey string

The key to use when caching the lexicon topic.

$entries array

An array of key => value pairs of lexicon entries.

$options array

An optional array of caching options.

Returns
Type Description
array An array representing the lexicon topic cache.
Details
Access
public  
methodpublicgenerateObject( \xPDOObject $obj, string $objName, boolean $generateObjVars = false, boolean $generateRelated = false, string $objRef = 'this->xpdo', boolean $format = xPDOCacheManager::CACHE_PHP ) : string
inherited

Generate a PHP executable representation of an xPDOObject.

Inherited from: \xPDOCacheManager::generateObject()
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  
methodpublicgenerateResource( \modResource $obj, array $options = array() ) : array

Generates a cache entry for a Resource or Resource-derived object.

Resource classes can define their own cacheKey.

Parameters
Name Type Description
$obj \modResource

The Resource instance to be cached.

$options array

Options for resource generation.

Returns
Type Description
array The generated resource representation.
methodpublicgenerateScript( \modScript $objElement, string $objContent = null, array $options = array() ) : boolean | string

Generates a file representing an executable modScript function.

Parameters
Name Type Description
$objElement \modScript

A {@link modScript} instance to generate the script file for.

$objContent string

Optional script content to override the persistent instance.

$options array

An array of additional options for the operation.

Returns
Type Description
boolean | string The actual generated source content representing the modScript or false if the source content could not be generated.
methodpublicget( string $key, array $options = array() ) : mixed
inherited

Get a value from a cache provider by key.

Inherited from: \xPDOCacheManager::get()
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
inherited

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

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

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

Inherited from: \xPDOCacheManager::getCacheProvider()
Parameters
Name Type Description
$key
$options
methodpublicgetElementMediaSourceCache(  $element,  $contextKey,  $options = array() ) : void

Parameters
Name Type Description
$element
$contextKey
$options
methodpublicgetFilePermissions( ) : integer
inherited

Get default file permissions based on umask

Inherited from: \xPDOCacheManager::getFilePermissions()
Returns
Type Description
integer The default file permissions.
methodpublicgetFolderPermissions( ) : integer
inherited

Get default folder permissions based on umask

Inherited from: \xPDOCacheManager::getFolderPermissions()
Returns
Type Description
integer The default folder permissions.
methodpublicgetOption( string $key, array $options = array(), mixed $default = null ) : mixed
inherited

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

Inherited from: \xPDOCacheManager::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 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
inherited

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

Inherited from: \xPDOCacheManager::matches()
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() ) : boolean

Implements MODX cache refresh process, converting cache partitions to cache providers.

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

Parameters
Name Type Description
$providers array
$results array
Returns
Type Description
boolean
methodpublicreplace( string $key, mixed $var, integer $lifetime = 0, array $options = array() ) : boolean
inherited

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

Inherited from: \xPDOCacheManager::replace()
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
inherited

Set a key-value pair in a cache provider.

Inherited from: \xPDOCacheManager::set()
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
inherited

Writes a file to the filesystem.

Inherited from: \xPDOCacheManager::writeFile()
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
inherited

Recursively writes a directory tree of files to the filesystem

Inherited from: \xPDOCacheManager::writeTree()
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  
Documentation was generated by DocBlox 0.18.1.