Xataface 2.0
Xataface Application Framework
Public Member Functions | Data Fields
Dataface_OutputCache Class Reference

Public Member Functions

 Dataface_OutputCache ($params=array())
 getUserId ()
 _buildPageSelect ($params=array())
 getPage ($params=array())
 numCurrentVersions ($params=array())
 ob_start ($params=array())
 ob_flush ($data)
 getPageID ($params=array())
 cachePage ($params=array())
 _gzipGetFourChars ($Val)
 _createCacheTable ()
 _cacheTableExists ()
 cleanCache ()
 gzipSupported ()
getTableModificationTimes ()
 isModified ($time, $tables=null)

Data Fields

 $useGzipCompression = true
 $tableName = '__output_cache'
 $ignoredTables = array()
 $observedTables = array()
 $exemptActions = array()
 $stripKeys = array('-l','-lang')
 $app
 $threshold = 0.1
 $tableModificationTimes
 $lifeTime = 360000
 $randomize = 0
 $_cacheTableExists = null
 $lastModified = null
 $headers = array()
 $userId = null
 $usedTables = array()

Detailed Description

A class to handle caching of output. It takes into account whether database tables have been updated to decide whether a cached version is valid or not.

Definition at line 6 of file OutputCache.php.


Member Function Documentation

_buildPageSelect ( params = array())

Builds the where clause for a select statement to get cached versions of pages from the database.

Definition at line 72 of file OutputCache.php.

_cacheTableExists ( )

Checks if the database table to store the cached pages already exists. if it doesn't we shall have to create it.

Returns:
boolean

Definition at line 552 of file OutputCache.php.

_createCacheTable ( )

Creates the table to store the cached pages.

Definition at line 526 of file OutputCache.php.

_gzipGetFourChars ( Val)

A utility script to get 4 characters from the size or CRC of a gzip file. Borrowed from php.net (http://ca.php.net/gzcompress).

Definition at line 512 of file OutputCache.php.

cachePage ( params = array())

Saves a page into the database. This will save both the raw text and a gzipped version (if the zlib extension is present).

Parameters:
$paramsAn associative array of parameters:
idThe Page id to store this data as. This is a required field It is stored as a VARCHAR(64) so it can be any string not longer than 64 characters.
dataThe content of the page to be cached. Required.
langThe language of the content. Optional. Will default to the currently selected language ($app->_conf['lang']).
userThe username of the user that this page is cached for. Defaults to currently logged in user.
expiresThe unix timestamp when this page will expire. Optional. Defaults to NOW + $this->lifeTime (usually 3600 seconds).
tablesAn array or comma-delimited list of table names that This page depends on. If these tables have been updated after the cache is created then the cache is invalidated. An optional integer number of versions of this page that should stay on random rotation.

Definition at line 351 of file OutputCache.php.

cleanCache ( )

Deletes all expired pages from the cache.

Definition at line 564 of file OutputCache.php.

Dataface_OutputCache ( params = array())

Definition at line 29 of file OutputCache.php.

getPage ( params = array())

Obtains the cached version of a page.

Parameters:
$paramsAssociative array of parameters:
idThe Page ID of the page we wish to obtain. This is stored as a VARCHAR(64) so it can be any string not longer than 64 characters.
langThe language of the page (e.g. en, fr, zh, etc...). This will default to the currently logged in user
userThe user id of the user accessing the page. This will default to the currently logged in user.
Returns:
The cached content (possibly gzip compressed). Or null if there was no valid cached version.

Definition at line 106 of file OutputCache.php.

getPageID ( params = array())

Definition at line 320 of file OutputCache.php.

& getTableModificationTimes ( )

Returns an associative array of table names and their associated update times as unix timestamps. eg: [Tablename] -> [Unix Timestamp]

Definition at line 582 of file OutputCache.php.

getUserId ( )

Definition at line 48 of file OutputCache.php.

gzipSupported ( )

Indicates whether the user's browser supports gzip compression. This is important because, if it does, then we will be using the GZIP compressed versions of cached pages to save bandwidth and reduce latency.

Definition at line 573 of file OutputCache.php.

isModified ( time,
tables = null 
)

Checks to see if any of the specified tables have been modified since a given time. Note that the tables stored in $this->observedTables will automatically be added to $tables for this check. $this->observedTables is an array of tablenames that must always be observed.

Parameters:
$timeThe unix timestamp that we are checking against.
$tablesAn array (or comma-delimited string) of table names
Returns:
True if the tables have been modified since $time. False otherwise.

Definition at line 599 of file OutputCache.php.

numCurrentVersions ( params = array())

Returns the number of versions of a page there are still current.

Parameters:
$paramsAssociative array of parameters:
idThe Page ID of the page we wish to obtain. This is stored as a VARCHAR(64) so it can be any string not longer than 64 characters.
langThe language of the page (e.g. en, fr, zh, etc...). This will default to the currently logged in user
userThe user id of the user accessing the page. This will default to the currently logged in user.
Returns:
Integer number of current versions.

Definition at line 151 of file OutputCache.php.

ob_flush ( data)

Definition at line 290 of file OutputCache.php.

ob_start ( params = array())

Starts buffering output. This will first check for a cached version of the current page, however, and output that to the browser. If that fails, then this will turn on output buffering and register the OutputCache::ob_flush() method (in this class) to can called when the script finishes - or when ob_flush() is called.

Parameters:
$paramsAssociative array of parameters:
idThe Page id to store this data as. Optional. If omitted Then an md5 hash of the current REQUEST_URI is used as the ID. It is stored as a VARCHAR(64) so it can be any string not longer than 64 characters.
dataThe content of the page to be cached. Required.
langThe language of the content. Optional. Will default to the currently selected language ($app->_conf['lang']).
userThe username of the user that this page is cached for. Defaults to currently logged in user.
expiresThe unix timestamp when this page will expire. Optional. Defaults to NOW + $this->lifeTime (usually 3600 seconds).
tablesAn array or comma-delimited list of table names that This page depends on. If these tables have been updated after the cache is created then the cache is invalidated. An optional integer number of versions of this page that should stay on random rotation.

Definition at line 190 of file OutputCache.php.


Field Documentation

$_cacheTableExists = null

Definition at line 19 of file OutputCache.php.

$app

Definition at line 14 of file OutputCache.php.

$exemptActions = array()

Definition at line 12 of file OutputCache.php.

$headers = array()

Definition at line 21 of file OutputCache.php.

$ignoredTables = array()

Definition at line 10 of file OutputCache.php.

$lastModified = null

Definition at line 20 of file OutputCache.php.

$lifeTime = 360000

Definition at line 17 of file OutputCache.php.

$observedTables = array()

Definition at line 11 of file OutputCache.php.

$randomize = 0

Definition at line 18 of file OutputCache.php.

$stripKeys = array('-l','-lang')

Definition at line 13 of file OutputCache.php.

$tableModificationTimes

Definition at line 16 of file OutputCache.php.

$tableName = '__output_cache'

Definition at line 9 of file OutputCache.php.

$threshold = 0.1

Definition at line 15 of file OutputCache.php.

$usedTables = array()

A list of the tables that have been used in the current request.

Definition at line 27 of file OutputCache.php.

$useGzipCompression = true

Definition at line 8 of file OutputCache.php.

$userId = null

Definition at line 22 of file OutputCache.php.


The documentation for this class was generated from the following file:
 All Data Structures Namespaces Files Functions Variables Enumerations