Documentation

Cache extends CacheLib

Cache

Tags
copyright

CLOUDREXX CMS - CLOUDREXX AG

author

Cloudrexx Development Team info@cloudrexx.com

version
3.1.2
subpackage

coremodule_cache

Table of Contents

Constants

CACHE_DIRECTORY_OFFSET_ESI  = 'esi/'
ESI cache directory offset
CACHE_DIRECTORY_OFFSET_PAGE  = 'page/'
Page cache directory offset
CACHE_ENGINE_APC  = 'apc'
Alternative PHP Cache extension
CACHE_ENGINE_MEMCACHE  = 'memcache'
memcache extension
CACHE_ENGINE_MEMCACHED  = 'memcached'
memcache(d) extension
CACHE_ENGINE_OFF  = 'off'
cache off
CACHE_ENGINE_XCACHE  = 'xcache'
xcache extension
CACHE_ENGINE_ZEND_OPCACHE  = 'zendopcache'
zend opcache extension
HTTP_STATUS_CODE_HEADER  = 'X-StatusCode'
LOCALE_CACHE_FILE_NAME  = 'Locale.dat'
File name for page cache locale data

Properties

$arrCacheablePages  : mixed
$boolIsEnabled  : mixed
$strCacheFilename  : mixed
$strCachePath  : mixed
$apiUrlString  : string
$arrPageContent  : array<string|int, mixed>
Page info (url, locale, ...)
$cacheIncrement  : int
Number added to $cachePrefix to allow "invalidating" the cache
$cachePrefix  : string
Prefix to be used to identify cache entries in shared caching environments.
$doctrineCacheEngine  : AbstractCache
$dynFuncs  : array<string|int, mixed>
Dynamic ESI variable callbacks
$dynVars  : array<string|int, mixed>
Dynamic ESI variable callbacks
$exceptions  : array<string|int, mixed>
$forceUserbased  : bool
$intCacingTime  : int
$jsonData  : JsonData
$memcache  : mixed
$memcached  : mixed
$opCacheEngine  : mixed
$opCacheEngines  : array<string|int, mixed>
Used op cache engines
$ssiProxy  : ReverseProxyProxy
$userCacheEngine  : mixed
$userCacheEngines  : type
Used user cache engines

Methods

__construct()  : mixed
Constructor
_deleteAllFiles()  : mixed
Delete all cached file's of the cache system
addException()  : mixed
clearCache()  : mixed
Flush all cache instances
clearReverseProxyCache()  : mixed
Drops a cache page on reverse proxy cache
clearSsiCache()  : mixed
Drops all cached ESI/SSI elements
clearSsiCachePage()  : mixed
Drops the ESI cache for a specific call
clearUserBasedEsiCache()  : mixed
Clear user based ESI cache
clearUserBasedPageCache()  : mixed
Clear user based page cache
deactivateNotUsedOpCaches()  : mixed
deleteComponentFiles()  : mixed
Delete all cached files for a component from cache-folder
deleteNonPagePageCache()  : mixed
Drops all page cache files that do not belong to a page Those are cached header redirects
deleteSingleFile()  : mixed
Delete all specific file from cache-folder
endContrexxCaching()  : mixed
End caching functions. Check for a sessionId: if not set, write pagecontent to a file.
forceClearCache()  : mixed
Calls the Clear Function for the given cache engine
forceUserbasedPageCache()  : mixed
Forces page cache to be stored per user
getAllOpCacheEngines()  : mixed
getAllUserCacheEngines()  : mixed
getCacheFileNameFromUrl()  : string
Gets the local cache file name for an URL
getCacheFileNameSearchPartsFromUrl()  : array<string|int, mixed>
Returns the validated file search parts of the URL
getDoctrineCacheDriver()  : AbstractCache
Detects the correct doctrine cache driver for the user caching engine in use
getEsiContent()  : string
Returns the ESI/SSI content for a (json)data call
getMemcache()  : mixed
getMemcached()  : Memcache
getOpCacheActive()  : mixed
getOpCacheEngine()  : mixed
getRandomizedEsiContent()  : string
Each entry of $esiContentInfos consists of an array like: array( <adapterName>, <adapterMethod>, <params>, )
getSettings()  : array<string|int, mixed>
Creates an array containing all important cache-settings
getSsiProxy()  : ReverseProxy
Returns the current SSI proxy
getUserCacheActive()  : mixed
getUserCacheEngine()  : mixed
initEsiDynVars()  : mixed
Loads dynamic ESI variables and functions
internalEsiParsing()  : string
Parses ESI directives internally if configured to do so
isException()  : bool
This parses the list of exceptions (defined in endContrexxCaching()), which will not be cached. Each entry can be: - A component name, this will stop caching for the whole component - An array with the component name as key and a list of conditions as value. In that case, the sub-conditions can either be a cmd of the component or a callback (function($page) {}) which returns true if the exception matches and false otherwise.
parseEsiVars()  : string
Parses the dynamic ESI variables and functions in the given content
setCachedLocaleData()  : mixed
Sets the cached locale data
setCachePrefix()  : mixed
Overwrite the automatically set CachePrefix
startContrexxCaching()  : mixed
Start caching functions. If this page is already cached, load it, otherwise create new file
writeCacheFileForRequest()  : mixed
Writes the cache file for the current request
checkCacheDir()  : mixed
Makes sure that the cache directory exists and is writable
cleanupCacheFiles()  : mixed
Removes all page cache files for a request
clearMemcached()  : mixed
Clears all Memcacheddata related to this Domain if Memcache is installed
getActivatedCacheEngines()  : mixed
getApiResponseForUrl()  : string
Returns the content of the API response for an API URL This gets data internally and does not do a HTTP request!
getCachedLocaleData()  : array<string|int, mixed>
Returns the cached locale data
getCachePrefix()  : string
Retunrns the CachePrefix related to this Domain
getDomainsAndPorts()  : array<string|int, mixed>
Returns all domains and ports this instance of cloudrexx can be reached at
getMemcacheConfiguration()  : mixed
getMemcachedConfiguration()  : mixed
getReverseProxyConfiguration()  : array<string|int, mixed>
Gets the configuration value for reverse proxy
getSsiProcessorConfiguration()  : array<string|int, mixed>
Gets the configuration value for external ESI/SSI processor
getUrlFromApi()  : Url
Wrapper for \Cx\Core\Routing\Url::fromApi() This ensures correct param order
initContrexxCaching()  : mixed
initOPCaching()  : mixed
initRequestInfo()  : mixed
Initializes basic request info (url, locale, ...)
initUserCaching()  : mixed
isActive()  : mixed
isConfigured()  : mixed
isInstalled()  : mixed
selectBestLanguageFromRequest()  : array<string|int, mixed>
Returns the necessary data to later identify the matching locale
setCachePath()  : mixed
Sets the cache path
clearApc()  : mixed
Clears APC cache if APC is installed
clearMemcache()  : mixed
Clears all Memcachedata related to this Domain if Memcache is installed
clearXcache()  : mixed
Clears XCache if configured. Configuration is needed to clear.
clearZendOpCache()  : mixed
Clears Zend OPCache if installed

Constants

CACHE_DIRECTORY_OFFSET_ESI

ESI cache directory offset

public mixed CACHE_DIRECTORY_OFFSET_ESI = 'esi/'

CACHE_DIRECTORY_OFFSET_PAGE

Page cache directory offset

public mixed CACHE_DIRECTORY_OFFSET_PAGE = 'page/'

CACHE_ENGINE_APC

Alternative PHP Cache extension

public mixed CACHE_ENGINE_APC = 'apc'

CACHE_ENGINE_MEMCACHE

memcache extension

public mixed CACHE_ENGINE_MEMCACHE = 'memcache'

CACHE_ENGINE_MEMCACHED

memcache(d) extension

public mixed CACHE_ENGINE_MEMCACHED = 'memcached'

CACHE_ENGINE_OFF

cache off

public mixed CACHE_ENGINE_OFF = 'off'

CACHE_ENGINE_XCACHE

xcache extension

public mixed CACHE_ENGINE_XCACHE = 'xcache'

CACHE_ENGINE_ZEND_OPCACHE

zend opcache extension

public mixed CACHE_ENGINE_ZEND_OPCACHE = 'zendopcache'

HTTP_STATUS_CODE_HEADER

public mixed HTTP_STATUS_CODE_HEADER = 'X-StatusCode'

LOCALE_CACHE_FILE_NAME

File name for page cache locale data

public mixed LOCALE_CACHE_FILE_NAME = 'Locale.dat'

Properties

$arrCacheablePages

public mixed $arrCacheablePages = array()

$apiUrlString

protected string $apiUrlString = ''

This cannot be set to it's value until DB is initialized (since Url::from* needs DB)

$arrPageContent

Page info (url, locale, ...)

protected array<string|int, mixed> $arrPageContent = array()

$cacheIncrement

Number added to $cachePrefix to allow "invalidating" the cache

protected int $cacheIncrement = 1

$cachePrefix

Prefix to be used to identify cache entries in shared caching environments.

protected string $cachePrefix

$doctrineCacheEngine

protected AbstractCache $doctrineCacheEngine = null

doctrine cache engine for the active user cache engine

$dynFuncs

Dynamic ESI variable callbacks

protected array<string|int, mixed> $dynFuncs = array()

$dynVars

Dynamic ESI variable callbacks

protected array<string|int, mixed> $dynVars = array()

$exceptions

protected array<string|int, mixed> $exceptions = array()

List of exceptions which will not be cached For format see isException()

$forceUserbased

protected bool $forceUserbased = false

Whether to store page cache user based or not

$intCacingTime

protected int $intCacingTime

Cache lease time in seconds

$opCacheEngines

Used op cache engines

protected array<string|int, mixed> $opCacheEngines = array()

Cache engine names, empty for none

$userCacheEngines

Used user cache engines

protected type $userCacheEngines = array()

array Cache engine names, empty for none

Methods

__construct()

Constructor

public __construct() : mixed
Tags
global

array $_CONFIG

_deleteAllFiles()

Delete all cached file's of the cache system

public _deleteAllFiles([mixed $cacheEngine = null ]) : mixed
Parameters
$cacheEngine : mixed = null

clearCache()

Flush all cache instances

public clearCache([string $cacheEngine = null ][, bool $includingEsi = true ]) : mixed
Parameters
$cacheEngine : string = null

See CACHE_ENGINE_* constants

$includingEsi : bool = true

(optional) Whether to drop ESI cache

Tags
see
PageEventListener

on update of page objects

clearReverseProxyCache()

Drops a cache page on reverse proxy cache

public clearReverseProxyCache(mixed $urlPattern) : mixed
Parameters
$urlPattern : mixed

clearSsiCache()

Drops all cached ESI/SSI elements

public clearSsiCache([mixed $urlPattern = '' ]) : mixed
Parameters
$urlPattern : mixed = ''

clearSsiCachePage()

Drops the ESI cache for a specific call

public clearSsiCachePage(string $adapterName, string $adapterMethod[, array<string|int, mixed> $params = array() ]) : mixed
Parameters
$adapterName : string

(Json)Data adapter name

$adapterMethod : string

(Json)Data method name

$params : array<string|int, mixed> = array()

(optional) params for (Json)Data method call

Tags
todo

Only drop this specific content instead of complete cache

clearUserBasedEsiCache()

Clear user based ESI cache

public clearUserBasedEsiCache([string $sessionId = '' ]) : mixed

If argument $sessionId is set, then only the cache of the user (identified by sessionid $sessionId) will be flushed. Otherwise (if $sessionId is not set), the complete user based cache is flushed.

Parameters
$sessionId : string = ''

The session ID of the user of whom to clear the esi cache from. If not set, then all used based cach is flusehd.

clearUserBasedPageCache()

Clear user based page cache

public clearUserBasedPageCache([string $sessionId = '' ]) : mixed

If argument $sessionId is set, then only the cache of the user (identified by sessionid $sessionId) will be flushed. Otherwise (if $sessionId is not set), the complete user based cache is flushed.

Parameters
$sessionId : string = ''

The session ID of the user of whom to clear the page cache from. If not set, then all used based cach is flusehd.

deactivateNotUsedOpCaches()

public deactivateNotUsedOpCaches() : mixed

deleteComponentFiles()

Delete all cached files for a component from cache-folder

public deleteComponentFiles(mixed $componentName) : mixed
Parameters
$componentName : mixed

deleteNonPagePageCache()

Drops all page cache files that do not belong to a page Those are cached header redirects

public deleteNonPagePageCache() : mixed

deleteSingleFile()

Delete all specific file from cache-folder

public deleteSingleFile(mixed $intPageId) : mixed
Parameters
$intPageId : mixed

endContrexxCaching()

End caching functions. Check for a sessionId: if not set, write pagecontent to a file.

public endContrexxCaching(mixed $page, mixed $endcode) : mixed
Parameters
$page : mixed
$endcode : mixed

forceClearCache()

Calls the Clear Function for the given cache engine

public forceClearCache([string $cacheEngine = null ]) : mixed
Parameters
$cacheEngine : string = null

forceUserbasedPageCache()

Forces page cache to be stored per user

public forceUserbasedPageCache() : mixed

getAllUserCacheEngines()

public getAllUserCacheEngines() : mixed

getCacheFileNameFromUrl()

Gets the local cache file name for an URL

public getCacheFileNameFromUrl(string $url, string $originalUrl[, bool $withCacheInfoPart = true ]) : string
Parameters
$url : string

URL to get file name for

$originalUrl : string

URL of the page that ESI is parsed for

$withCacheInfoPart : bool = true

(optional) Adds info part (default true)

Return values
string

File name (without path)

getCacheFileNameSearchPartsFromUrl()

Returns the validated file search parts of the URL

public getCacheFileNameSearchPartsFromUrl(string $url, string $originalUrl) : array<string|int, mixed>
Parameters
$url : string

URL to parse

$originalUrl : string

URL of the page that ESI is parsed for

Return values
array<string|int, mixed>

<fileNamePrefix>=><parsedValue> type array

getDoctrineCacheDriver()

Detects the correct doctrine cache driver for the user caching engine in use

public getDoctrineCacheDriver() : AbstractCache
Return values
AbstractCache

The doctrine cache driver object

getEsiContent()

Returns the ESI/SSI content for a (json)data call

public getEsiContent(string $adapterName, string $adapterMethod[, array<string|int, mixed> $params = array() ]) : string
Parameters
$adapterName : string

(Json)Data adapter name

$adapterMethod : string

(Json)Data method name

$params : array<string|int, mixed> = array()

(optional) params for (Json)Data method call

Return values
string

ESI/SSI directives to put into HTML code

getMemcached()

public getMemcached() : Memcache
Return values
Memcache

The memcached object

getRandomizedEsiContent()

Each entry of $esiContentInfos consists of an array like: array( <adapterName>, <adapterMethod>, <params>, )

public getRandomizedEsiContent(array<string|int, mixed> $esiContentInfos[, int $count = 1 ]) : string
Parameters
$esiContentInfos : array<string|int, mixed>

List of ESI content info arrays

$count : int = 1

(optional) Number of unique random entries to parse

Return values
string

ESI randomized include code

getSettings()

Creates an array containing all important cache-settings

public getSettings() : array<string|int, mixed>
Tags
global

object $objDatabase

Return values
array<string|int, mixed>

$arrSettings

initEsiDynVars()

Loads dynamic ESI variables and functions

public initEsiDynVars() : mixed

internalEsiParsing()

Parses ESI directives internally if configured to do so

public internalEsiParsing(string $htmlCode[, mixed $cxNotYetInitialized = false ]) : string
Parameters
$htmlCode : string

HTML code to replace ESI directives in

$cxNotYetInitialized : mixed = false
Return values
string

Parsed HTML code

isException()

This parses the list of exceptions (defined in endContrexxCaching()), which will not be cached. Each entry can be: - A component name, this will stop caching for the whole component - An array with the component name as key and a list of conditions as value. In that case, the sub-conditions can either be a cmd of the component or a callback (function($page) {}) which returns true if the exception matches and false otherwise.

public isException(mixed $page, Page $cx) : bool
  • A callback (function($cx, $page) }) which returns true if the exception matches and false otherwise.
Parameters
$page : mixed
$cx : Page

Current page

Return values
bool

True if current request matches an exception, false otherwise

parseEsiVars()

Parses the dynamic ESI variables and functions in the given content

public parseEsiVars(string $content) : string
Parameters
$content : string

Content to parse

Return values
string

Parsed content

setCachedLocaleData()

Sets the cached locale data

public setCachedLocaleData(Cx $cx) : mixed

Default locale and the following hashtables are cached: <localeCode> to <localeId> <localeCountryCode> to <localeCodes>

Parameters
$cx : Cx

Cx instance

setCachePrefix()

Overwrite the automatically set CachePrefix

public setCachePrefix([ $prefix = '' ]) : mixed
Parameters
$prefix : = ''

String The new CachePrefix to be used. Setting an empty string will reset the CachePrefix to its initial value.

startContrexxCaching()

Start caching functions. If this page is already cached, load it, otherwise create new file

public startContrexxCaching(mixed $cx) : mixed
Parameters
$cx : mixed

writeCacheFileForRequest()

Writes the cache file for the current request

public writeCacheFileForRequest(Page $page, array<string|int, mixed> $headers, string $endcode[, mixed $forceUserbased = false ]) : mixed
Parameters
$page : Page

Current page (might be null for redirects before postResolve)

$headers : array<string|int, mixed>

List of headers set for the current response

$endcode : string

Current response

$forceUserbased : mixed = false

checkCacheDir()

Makes sure that the cache directory exists and is writable

protected checkCacheDir(Cx $cx) : mixed
Parameters
$cx : Cx

The contrexx instance

cleanupCacheFiles()

Removes all page cache files for a request

protected cleanupCacheFiles(string $filename, int $pageId, bool $userbased) : mixed
Parameters
$filename : string

Request hash (as in $this->strCacheFilename)

$pageId : int

Page ID

$userbased : bool

True if the current request is userbased, false otherwise

clearMemcached()

Clears all Memcacheddata related to this Domain if Memcache is installed

protected clearMemcached() : mixed

getActivatedCacheEngines()

protected getActivatedCacheEngines() : mixed

getApiResponseForUrl()

Returns the content of the API response for an API URL This gets data internally and does not do a HTTP request!

protected getApiResponseForUrl(string $url[, Response|null &$responseObj = null ]) : string
Parameters
$url : string

API URL

$responseObj : Response|null = null

(optional) Response object

Tags
throws
Exception

If JsonAdapter request did not succeed

Return values
string

API content or empty string

getCachedLocaleData()

Returns the cached locale data

protected getCachedLocaleData() : array<string|int, mixed>

Default locale and the following hashtables are cached: <localeCode> to <localeId> <localeCountryCode> to <localeCodes>

Return values
array<string|int, mixed>

Cached locale data or empty array

getCachePrefix()

Retunrns the CachePrefix related to this Domain

protected getCachePrefix([bool $withoutIncrement = false ]) : string
Parameters
$withoutIncrement : bool = false

(optional) If set to true returns the prefix without the increment

Tags
global

string $_DBCONFIG

Return values
string

CachePrefix

getDomainsAndPorts()

Returns all domains and ports this instance of cloudrexx can be reached at

protected getDomainsAndPorts() : array<string|int, mixed>
Return values
array<string|int, mixed>

List of domains and ports (array(array(0=>{domain}, 1=>{port})))

getMemcacheConfiguration()

protected getMemcacheConfiguration() : mixed

getMemcachedConfiguration()

protected getMemcachedConfiguration() : mixed

getReverseProxyConfiguration()

Gets the configuration value for reverse proxy

protected getReverseProxyConfiguration() : array<string|int, mixed>
Return values
array<string|int, mixed>

'ip' and 'port' of reverse proxy

getSsiProcessorConfiguration()

Gets the configuration value for external ESI/SSI processor

protected getSsiProcessorConfiguration() : array<string|int, mixed>
Return values
array<string|int, mixed>

'ip' and 'port' of external ESI/SSI processor

getUrlFromApi()

Wrapper for \Cx\Core\Routing\Url::fromApi() This ensures correct param order

protected getUrlFromApi(string $adapterName, string $adapterMethod, array<string|int, mixed> $params) : Url
Parameters
$adapterName : string

(Json)Data adapter name

$adapterMethod : string

(Json)Data method name

$params : array<string|int, mixed>

(optional) params for (Json)Data method call

Return values
Url

URL for (Json)Data call

initContrexxCaching()

protected initContrexxCaching() : mixed

initRequestInfo()

Initializes basic request info (url, locale, ...)

protected initRequestInfo() : mixed

isActive()

protected isActive(mixed $cacheEngine) : mixed
Parameters
$cacheEngine : mixed

isConfigured()

protected isConfigured(mixed $cacheEngine[, mixed $user = false ]) : mixed
Parameters
$cacheEngine : mixed
$user : mixed = false

isInstalled()

protected isInstalled(mixed $cacheEngine) : mixed
Parameters
$cacheEngine : mixed

selectBestLanguageFromRequest()

Returns the necessary data to later identify the matching locale

protected selectBestLanguageFromRequest(Cx $cx) : array<string|int, mixed>

This method does not use database or cached database data

Parameters
$cx : Cx

Cx instance

Return values
array<string|int, mixed>

Locale info

setCachePath()

Sets the cache path

protected setCachePath() : mixed

clearApc()

Clears APC cache if APC is installed

private clearApc() : mixed

clearMemcache()

Clears all Memcachedata related to this Domain if Memcache is installed

private clearMemcache() : mixed

clearXcache()

Clears XCache if configured. Configuration is needed to clear.

private clearXcache() : mixed

clearZendOpCache()

Clears Zend OPCache if installed

private clearZendOpCache() : mixed

        
On this page

Search results