core/xpdo/cache/xpdocachemanager.class.php
Classes implementing a default cache implementation for xPDO.
- Package
- xpdo
- Subpackage
- cache
\xPDOCache
An abstract class that defines the methods a cache provider must implement.
Properties
Methods
add(
string $key, string $var, integer $expire
=
0, array $options
=
array()
)
:
boolean
Adds a value to the cache.
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. |
Type | Description |
---|---|
boolean | True if successful |
- Access
- public
delete(
string $key, array $options
=
array()
)
:
boolean
Deletes a value from the cache.
Name | Type | Description |
---|---|---|
$key | string | A unique key identifying the item being deleted. |
$options | array | Additional options for the operation. |
Type | Description |
---|---|
boolean | True if successful |
- Access
- public
flush(
array $options
=
array()
)
:
boolean
Flush all values from the cache.
Name | Type | Description |
---|---|---|
$options | array | Additional options for the operation. |
Type | Description |
---|---|
boolean | True if successful. |
- Access
- public
get(
string $key, array $options
=
array()
)
:
mixed
Gets a value from the cache.
Name | Type | Description |
---|---|---|
$key | string | A unique key identifying the item to fetch. |
$options | array | Additional options for the operation. |
Type | Description |
---|---|
mixed | The value retrieved from the cache. |
- Access
- public
getCacheKey(
string $key, array $options
=
array()
)
:
string
Get the actual cache key the implementation will use.
Name | Type | Description |
---|---|---|
$key | string | The identifier the application uses. |
$options | array | Additional options for the operation. |
Type | Description |
---|---|
string | The identifier with any implementation specific prefixes or other transformations applied. |
getOption(
string $key, array $options
=
array(), mixed $default
=
null
)
:
mixed
Get an option from supplied options, the cache options, or the xpdo config.
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. |
Type | Description |
---|---|
mixed | The value of the option. |
isInitialized(
)
:
boolean
Indicates if this xPDOCache instance has been properly initialized.
Type | Description |
---|---|
boolean | true if the implementation was initialized successfully. |
replace(
string $key, string $var, integer $expire
=
0, array $options
=
array()
)
:
boolean
Replaces a value in the cache.
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. |
Type | Description |
---|---|
boolean | True if successful |
- Access
- public
set(
string $key, string $var, integer $expire
=
0, array $options
=
array()
)
:
boolean
Sets a value in the cache.
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. |
Type | Description |
---|---|
boolean | True if successful |
- Access
- public
\xPDOCacheManager
The default cache manager implementation for xPDO.
- Children
- \modCacheManager
Constants
Properties
Methods
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.
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. |
clean(
array $options
=
array()
)
:
boolean
Flush the contents of a cache provider.
Name | Type | Description |
---|---|---|
$options | array | Additional options for the cache flush. |
Type | Description |
---|---|
boolean | True if the flush was successful. |
- Access
- public
copyFile(
string $source, string $target, array $options
=
array()
)
:
boolean | array
Copies a file from a source file to a target directory.
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.
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
Delete a key-value pair from a cache provider.
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.
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.
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
Name | Type | Description |
---|---|---|
$s | string | The string to escape single quotes in. |
Type | Description |
---|---|
string | The string with single quotes escaped. |
- 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.
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
- Todo
- Complete $generateRelated functionality.
- Todo
- Add stdObject support.
get(
string $key, array $options
=
array()
)
:
mixed
Get a value from a cache provider by key.
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.
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.
Name | Type | Description |
---|---|---|
$key | ||
$options |
getFilePermissions(
)
:
integer
Get default file permissions based on umask
Type | Description |
---|---|
integer | The default file permissions. |
getFolderPermissions(
)
:
integer
Get default folder permissions based on umask
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.
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.
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()
)
:
array
Refresh specific or all cache providers.
The default behavior is to call clean() with the provided options
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. |
Type | Description |
---|---|
array | An array of results for each provider that is refreshed. |
replace(
string $key, mixed $var, integer $lifetime
=
0, array $options
=
array()
)
:
boolean
Replace a key-value pair in in a cache provider.
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
Set a key-value pair in a cache provider.
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
Writes a file to the filesystem.
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
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
\xPDOFileCache
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
$initialized= 'false'
false
Details- Type
- n/a
- Inherited_from
- \xPDOCache::$$initialized
$key= ''''
''
Details- Type
- n/a
- Inherited_from
- \xPDOCache::$$key
$options= 'array()'
array()
Details- Type
- n/a
- Inherited_from
- \xPDOCache::$$options
$xpdo= 'null'
null
Details- Type
- n/a
- Inherited_from
- \xPDOCache::$$xpdo
Methods
add(
string $key, string $var, integer $expire
=
0, array $options
=
array()
)
:
boolean
Adds a value to the cache.
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. |
Type | Description |
---|---|
boolean | True if successful |
delete(
string $key, array $options
=
array()
)
:
boolean
Deletes a value from the cache.
Name | Type | Description |
---|---|---|
$key | string | A unique key identifying the item being deleted. |
$options | array | Additional options for the operation. |
Type | Description |
---|---|
boolean | True if successful |
flush(
array $options
=
array()
)
:
boolean
Flush all values from the cache.
Name | Type | Description |
---|---|---|
$options | array | Additional options for the operation. |
Type | Description |
---|---|
boolean | True if successful. |
get(
string $key, array $options
=
array()
)
:
mixed
Gets a value from the cache.
Name | Type | Description |
---|---|---|
$key | string | A unique key identifying the item to fetch. |
$options | array | Additional options for the operation. |
Type | Description |
---|---|
mixed | The value retrieved from the cache. |
getCacheKey(
string $key, array $options
=
array()
)
:
string
Get the actual cache key the implementation will use.
Name | Type | Description |
---|---|---|
$key | string | The identifier the application uses. |
$options | array | Additional options for the operation. |
Type | Description |
---|---|
string | The identifier with any implementation specific prefixes or other transformations applied. |
getOption(
string $key, array $options
=
array(), mixed $default
=
null
)
:
mixed
Get an option from supplied options, the cache options, or the xpdo config.
Inherited from: \xPDOCache::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 xPDOCache implementation. |
$default | mixed | An optional default value to return if no value is found. |
Type | Description |
---|---|
mixed | The value of the option. |
isInitialized(
)
:
boolean
Indicates if this xPDOCache instance has been properly initialized.
Inherited from: \xPDOCache::isInitialized()Type | Description |
---|---|
boolean | true if the implementation was initialized successfully. |
replace(
string $key, string $var, integer $expire
=
0, array $options
=
array()
)
:
boolean
Replaces a value in the cache.
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. |
Type | Description |
---|---|
boolean | True if successful |
set(
string $key, string $var, integer $expire
=
0, array $options
=
array()
)
:
boolean
Sets a value in the cache.
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. |
Type | Description |
---|---|
boolean | True if successful |