core/model/modx/modcachemanager.class.php
Contains the xPDOCacheManager implementation for MODX.
- Package
- modx
\modCacheManager
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
CACHE_PHP
= 0
- Inherited_from
- \xPDOCacheManager::CACHE_PHP
CACHE_JSON
= 1
- Inherited_from
- \xPDOCacheManager::CACHE_JSON
CACHE_SERIALIZE
= 2
- Inherited_from
- \xPDOCacheManager::CACHE_SERIALIZE
CACHE_DIR
= 'objects/'
- Inherited_from
- \xPDOCacheManager::CACHE_DIR
LOG_DIR
= 'logs/'
- Inherited_from
- \xPDOCacheManager::LOG_DIR
Properties
$_umask= 'null'
null
Details- Type
- n/a
- Inherited_from
- \xPDOCacheManager::$$_umask
$caches= 'array()'
array()
Details- Type
- n/a
- Inherited_from
- \xPDOCacheManager::$$caches
$options= 'array()'
array()
Details- Type
- n/a
- Inherited_from
- \xPDOCacheManager::$$options
$xpdo= 'null'
null
Details- Type
- n/a
- Inherited_from
- \xPDOCacheManager::$$xpdo
Methods
__construct(
\$xpdo $xpdo, array $options
=
array()
)
:
void
Constructor for modCacheManager that overrides xPDOCacheManager constructor to assign modX reference
Name | Type | Description |
---|---|---|
$xpdo | \$xpdo | A reference to the xPDO/modX instance |
$options | array | An array of configuration options |
add(
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.
Inherited from: \xPDOCacheManager::add()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. |
autoPublish(
array $options
=
array()
)
:
array
Check for and process Resources with pub_date or unpub_date set to now or in past.
Name | Type | Description |
---|---|---|
$options | array | An array of options for the process. |
Type | Description |
---|---|
array | An array containing published and unpublished Resource counts. |
- Todo
- Implement Context-isolated auto-publishing.
clean(
array $options
=
array()
)
:
boolean
Name | Type | Description |
---|---|---|
$options | array | Additional options for the cache flush. |
Type | Description |
---|---|
boolean | True if the flush was successful. |
- Access
- public
clearCache(
array $paths
=
array(), array $options
=
array()
)
:
array
Clear part or all of the MODX cache.
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:
|
Type | Description |
---|---|
array |
- Deprecated
- Use refresh()
copyFile(
string $source, string $target, array $options
=
array()
)
:
boolean | array
Copies a file from a source file to a target directory.
Inherited from: \xPDOCacheManager::copyFile()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. |
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. |
- Access
- public
copyTree(
string $source, string $target, array $options
=
array()
)
:
array | boolean
Recursively copies a directory tree from a source directory to a target directory.
Inherited from: \xPDOCacheManager::copyTree()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. |
Type | Description |
---|---|
array | boolean | Returns an array of all files and folders that were copied or false. |
- Access
- public
delete(
string $key, array $options
=
array()
)
:
boolean
Name | Type | Description |
---|---|---|
$key | string | A unique key identifying the item being deleted. |
$options | array | Additional options for the cache deletion. |
Type | Description |
---|---|
boolean | True if the deletion was successful. |
- Access
- public
deleteTree(
string $dirname, array $options
=
array('deleteTop' => false, 'skipDirs' => false, 'extensions' => array('.cache.php'))
)
:
boolean
Recursively deletes a directory tree of files.
Inherited from: \xPDOCacheManager::deleteTree()Name | Type | Description |
---|---|---|
$dirname | string | An absolute path to the source directory to delete. |
$options | array | An array of options for this function. |
Type | Description |
---|---|
boolean | Returns true if the deletion was successful. |
- Access
- public
endsWith(
string $string, string | array $pattern
)
:
boolean
Sees if a string ends with a specific pattern or set of patterns.
Inherited from: \xPDOCacheManager::endsWith()Name | Type | Description |
---|---|---|
$string | string | The string to check. |
$pattern | string | array | The pattern or an array of patterns to check against. |
Type | Description |
---|---|
boolean | True if the string ends with the pattern or any of the patterns provided. |
- Access
- public
escapeSingleQuotes(
string $s
)
:
string
Escapes all single quotes in a string
Inherited from: \xPDOCacheManager::escapeSingleQuotes()Name | Type | Description |
---|---|---|
$s | string | The string to escape single quotes in. |
Type | Description |
---|---|
string | The string with single quotes escaped. |
- Access
- public
generateActionMap(
string $cacheKey, array $options
=
array()
)
:
array
Generates a cache file for the manager actions.
Name | Type | Description |
---|---|---|
$cacheKey | string | The key to use when caching the action map. |
$options | array | An array of options |
Type | Description |
---|---|
array | An array representing the action map. |
- Access
- public
generateConfig(
array $options
=
array()
)
:
array
Generates the system settings cache for a MODX site.
Name | Type | Description |
---|---|---|
$options | array | Options for system settings generation. |
Type | Description |
---|---|
array | The generated system settings array. |
generateContext(
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.
Name | Type | Description |
---|---|---|
$key | string | The modContext key to be cached. |
$options | array | Options for context settings generation. |
Type | Description |
---|---|
array | An array containing all the context variable values. |
- 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()
generateLexiconTopic(
string $cacheKey, array $entries
=
array(), array $options
=
array()
)
:
array
Generates a lexicon topic cache file from a collection of entries
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. |
Type | Description |
---|---|
array | An array representing the lexicon topic cache. |
- Access
- public
generateObject(
\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.
Inherited from: \xPDOCacheManager::generateObject()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. |
Type | Description |
---|---|
string | The source map file, in string format. |
- Access
- public
generateResource(
\modResource $obj, array $options
=
array()
)
:
array
Generates a cache entry for a Resource or Resource-derived object.
Resource classes can define their own cacheKey.
Name | Type | Description |
---|---|---|
$obj | \modResource | The Resource instance to be cached. |
$options | array | Options for resource generation. |
Type | Description |
---|---|
array | The generated resource representation. |
generateScript(
\modScript $objElement, string $objContent
=
null, array $options
=
array()
)
:
boolean | string
Generates a file representing an executable modScript function.
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. |
Type | Description |
---|---|
boolean | string | The actual generated source content representing the modScript or false if the source content could not be generated. |
get(
string $key, array $options
=
array()
)
:
mixed
Name | Type | Description |
---|---|---|
$key | string | A unique key identifying the item being retrieved. |
$options | array | Additional options for the cache retrieval. |
Type | Description |
---|---|
mixed | The value of the object cache key |
- Access
- public
getCachePath(
)
:
string
Get the absolute path to a writable directory for storing files.
Inherited from: \xPDOCacheManager::getCachePath()Type | Description |
---|---|
string | The absolute path of the xPDO cache directory. |
- Access
- public
getCacheProvider(
$key
=
'', $options
=
array()
)
:
void
Get an instance of a provider which implements the xPDOCache interface.
Inherited from: \xPDOCacheManager::getCacheProvider()Name | Type | Description |
---|---|---|
$key | ||
$options |
getElementMediaSourceCache(
$element, $contextKey, $options
=
array()
)
:
void
Name | Type | Description |
---|---|---|
$element | ||
$contextKey | ||
$options |
getFilePermissions(
)
:
integer
Get default file permissions based on umask
Inherited from: \xPDOCacheManager::getFilePermissions()Type | Description |
---|---|
integer | The default file permissions. |
getFolderPermissions(
)
:
integer
Get default folder permissions based on umask
Inherited from: \xPDOCacheManager::getFolderPermissions()Type | Description |
---|---|
integer | The default folder permissions. |
getOption(
string $key, array $options
=
array(), mixed $default
=
null
)
:
mixed
Get an option from supplied options, the cacheManager options, or xpdo itself.
Inherited from: \xPDOCacheManager::getOption()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. |
Type | Description |
---|---|
mixed | The value of the option. |
matches(
string $string, string | array $pattern
)
:
boolean
Sees if a string matches a specific pattern or set of patterns.
Inherited from: \xPDOCacheManager::matches()Name | Type | Description |
---|---|---|
$string | string | The string to check. |
$pattern | string | array | The pattern or an array of patterns to check against. |
Type | Description |
---|---|
boolean | True if the string matched the pattern or any of the patterns provided. |
- Access
- public
refresh(
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
Name | Type | Description |
---|---|---|
$providers | array | |
$results | array |
Type | Description |
---|---|
boolean |
replace(
string $key, mixed $var, integer $lifetime
=
0, array $options
=
array()
)
:
boolean
Replace a key-value pair in in a cache provider.
Inherited from: \xPDOCacheManager::replace()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. |
Type | Description |
---|---|
boolean | True if the replace was successful. |
- Access
- public
set(
string $key, mixed $var, integer $lifetime
=
0, array $options
=
array()
)
:
boolean
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. |
Type | Description |
---|---|
boolean | True if the set was successful |
- Access
- public
writeFile(
string $filename, string $content, string $mode
=
'wb', array $options
=
array()
)
:
boolean
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. |
Type | Description |
---|---|
boolean | Returns true if the file was successfully written. |
- Access
- public
writeTree(
string $dirname, array $options
=
array()
)
:
boolean
Recursively writes a directory tree of files to the filesystem
Inherited from: \xPDOCacheManager::writeTree()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. |
Type | Description |
---|---|
boolean | Returns true if the directory was successfully written. |
- Access
- public