kernel/classes/ezstaticcache.php

Show: inherited
Table of Contents

File containing the eZStaticCache class

Copyright
Copyright (C) 1999-2011 eZ Systems AS. All rights reserved.  
License
eZ Business Use License Agreement Version 2.0  
Package
kernel  
Version
4.6.0  

\eZStaticCache

Package: kernel

The eZStaticCache class manages the static cache system.

This class can be used to generate static cache files usable by the static cache system.

Generating static cache is done by instantiating the class and then calling generateCache(). For example:

$staticCache = new eZStaticCache();
$staticCache->generateCache();

To generate the URLs that must always be updated call generateAlwaysUpdatedCache()

Parent(s)
\ezpStaticCache

Constants

Constant  USER_AGENT = 'eZ Publish static cache generator'

User-Agent string

Properties

Propertyprivate  $actionList= 'array()'
static
Default valuearray()Details
Type
n/a
Propertyprivate\array(int=>string)  $alwaysUpdate= ''

An array with URLs that is to always be updated.

Details
Type
\array(int=>string)
Propertyprivate\array(int=>string)  $cachedSiteAccesses= 'array()'

An array with siteaccesses names that will be cached.

Default valuearray()Details
Type
\array(int=>string)
Propertyprivate\array(int=>string)  $cachedURLArray= 'array()'

Array of URLs to cache.

Default valuearray()Details
Type
\array(int=>string)
Propertyprivatestring  $hostName= ''

The name of the host to fetch HTML data from.

Details
Type
string
Deprecated
deprecated since version 4.4, site.ini.[SiteSettings].SiteURL is used instead  
Propertyprivateint  $maxCacheDepth= ''

The maximum depth of URLs that will be cached.

Details
Type
int
Propertyprivatestring  $staticStorage= ''

The base path for the directory where static files are placed.

Details
Type
string

Methods

methodpublic__construct( ) : void

Initialises the static cache object with settings from staticcache.ini.

methodprivateaddAction( string $action, array $parameters ) : void

This function adds an action to the list that is used at the end of the request to remove and regenerate static cache files.

Parameters
Name Type Description
$action string
$parameters array
methodpublicalwaysUpdateURLArray( ) : array

Getter method for {@link eZStaticCache::$alwaysUpdate}

These URLs are configured with AlwaysUpdateArray in staticcache.ini.

Returns
Type Description
array An array with URLs that is to always be updated.
Details
See
\eZStaticCache::generateAlwaysUpdatedCache()  
methodprivatebuildCacheDirPart( string $dir, string $siteAccess ) : array

A helper method used to create directory parts array

Parameters
Name Type Description
$dir string
$siteAccess string
Returns
Type Description
array
methodprivatebuildCacheDirPath( string $siteAccess ) : array

Generates a cache directory parts including path, siteaccess name, site URL depending on the match order type.

Parameters
Name Type Description
$siteAccess string
Returns
Type Description
array
methodprivatebuildCacheFilename( string $staticStorageDir, string $url ) : string

Generates a full path to the cache file (index.html) based on the input parameters.

Parameters
Name Type Description
$staticStorageDir string

The storage for cache files.

$url string

The URL for the current item, e.g /news

Returns
Type Description
string The full path to the cache file (index.html).
methodpubliccacheURL( string $url, int | false $nodeID = false, bool $skipExisting = false,  $delay = true ) : bool

Generates the caches for the url $url using the currently configured storageDirectory().

Parameters
Name Type Description
$url string

The URL to cache, e.g /news

$nodeID int | false

The ID of the node to cache, if supplied it will also cache content/view/full/xxx.

$skipExisting bool

If true it will not unlink existing cache files.

$delay
Returns
Type Description
bool
methodpubliccachedSiteAccesses( ) : array

Getter method for {@link eZStaticCache::$cachedSiteAccesses}

Returns
Type Description
array An array with site-access names that should be cached.
methodpubliccachedURLArray( ) : array

Getter method for {@link eZStaticCache::$cachedURLArray}

Returns
Type Description
array An array with URLs that is to be cached statically, the URLs may contain wildcards.
methodpublicexecuteActions( ) : void
static

This function goes over the list of recorded actions and excecutes them.

methodpublicgenerateAlwaysUpdatedCache( bool $quiet = false, \eZCLI | false $cli = false, bool $delay = true ) : void

Generates the caches for all URLs that must always be generated.

Parameters
Name Type Description
$quiet bool

If true then the function will not output anything.

$cli \eZCLI | false

The eZCLI object or false if no output can be done.

$delay bool
methodpublicgenerateCache( bool $force = false, bool $quiet = false, \eZCLI | false $cli = false, bool $delay = true ) : void

Generates the static cache from the configured INI settings.

Parameters
Name Type Description
$force bool

If true then it will create all static caches even if it is not outdated.

$quiet bool

If true then the function will not output anything.

$cli \eZCLI | false

The eZCLI object or false if no output can be done.

$delay bool
methodpublicgenerateNodeListCache( array $nodeList ) : void

Generates caches for all the urls of nodes in $nodeList.

The associative array must have on of these entries: - node_id - ID of the node - path_identification_string - The path_identification_string from the node table, is used to fetch the node ID if node_id is missing.

Parameters
Name Type Description
$nodeList array

An array with node entries, each entry is either the node ID or an associative array.

methodpublichostName( ) : string

Getter method for {@link eZStaticCache::$hostName}

Returns
Type Description
string The currently configured host-name.
Details
Deprecated
deprecated since version 4.4  
methodpublicmaxCacheDepth( ) : int

Getter method for {@link eZStaticCache::$maxCacheDepth}

Returns
Type Description
int The maximum depth in the url which will be cached.
methodpublicremoveURL( string $url ) : void

Removes the static cache file (index.html) and its directory if it exists.

The directory path is based upon the URL $url and the configured static storage dir.

Parameters
Name Type Description
$url string

The URL for the current item, e.g /news

methodpublicstorageDirectory( ) : string

Getter method for {@link eZStaticCache::$staticStorageDir}

Returns
Type Description
string The currently configured storage directory for the static cache.
methodprivatestoreCache( string $url, string $staticStorageDir, array $alternativeStaticLocations = array(), bool $skipUnlink = false, bool $delay = true ) : void

Stores the static cache for $url and hostname defined in site.ini.[SiteSettings].SiteURL for cached siteaccess by fetching the web page using {@link eZHTTPTool::getDataByURL()} and storing the fetched HTML data.

Parameters
Name Type Description
$url string

The URL to cache, e.g /news

$staticStorageDir string

The base directory for storing cache files.

$alternativeStaticLocations array
$skipUnlink bool

If true it will not unlink existing cache files.

$delay bool
methodpublicstoreCachedFile( string $file, string $content ) : void
static

Stores the cache file $file with contents $content.

Takes care of setting proper permissions on the new file.

Parameters
Name Type Description
$file string
$content string
Documentation was generated by DocBlox 0.18.1.