\Smarty_CacheResource_Pdo

PDO Cache Handler Allows you to store Smarty Cache files into your db.

Example table : CREATE TABLE smarty_cache ( id char(40) NOT NULL COMMENT 'sha1 hash', name varchar(250) NOT NULL, cache_id varchar(250) DEFAULT NULL, compile_id varchar(250) DEFAULT NULL, modified timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, expire timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', content mediumblob NOT NULL, PRIMARY KEY (id), KEY name (name), KEY cache_id (cache_id), KEY compile_id (compile_id), KEY modified (modified), KEY expire (expire) ) ENGINE=InnoDB Example usage : $cnx = new PDO("mysql:host=localhost;dbname=mydb", "username", "password"); $smarty->setCachingType('pdo'); $smarty->loadPlugin('Smarty_CacheResource_Pdo'); $smarty->registerCacheResource('pdo', new Smarty_CacheResource_Pdo($cnx, 'smarty_cache'));

Summary

Methods
Properties
Constants
populate()
populateTimestamp()
process()
writeCachedContent()
readCachedContent()
clearAll()
clear()
hasLock()
acquireLock()
releaseLock()
getCachedContent()
locked()
load()
__construct()
No public properties found
No constants found
fetch()
fetchTimestamp()
save()
delete()
fillStatementsWithTableName()
getFetchStatement()
inputContent()
outputContent()
getTableName()
$sysplugins
$fetchStatements
$insertStatement
$deleteStatement
$truncateStatement
$fetchColumns
$fetchTimestampColumns
$pdo
$table
$database
N/A
No private methods found
No private properties found
N/A

Properties

$sysplugins

$sysplugins : array

resource types provided by the core

Type

array

$fetchStatements

$fetchStatements : 

Type

$insertStatement

$insertStatement : 

Type

$deleteStatement

$deleteStatement : 

Type

$truncateStatement

$truncateStatement : 

Type

$fetchColumns

$fetchColumns : 

Type

$fetchTimestampColumns

$fetchTimestampColumns : 

Type

$pdo

$pdo : 

Type

$table

$table : 

Type

$database

$database : 

Type

Methods

populate()

populate(\Smarty_Template_Cached  $cached, \Smarty_Internal_Template  $_template) : void

populate Cached Object with meta data from Resource

Parameters

\Smarty_Template_Cached $cached

cached object

\Smarty_Internal_Template $_template

template object

populateTimestamp()

populateTimestamp(\Smarty_Template_Cached  $cached) : void

populate Cached Object with timestamp and exists from Resource

Parameters

\Smarty_Template_Cached $cached

process()

process(\Smarty_Internal_Template  $_template, \Smarty_Template_Cached  $cached = null, boolean  $update = false) : boolean

Read the cached template and process header

Parameters

\Smarty_Internal_Template $_template

template object

\Smarty_Template_Cached $cached

cached object

boolean $update

flag if called because cache update

Returns

boolean —

true or false if the cached content does not exist

writeCachedContent()

writeCachedContent(\Smarty_Internal_Template  $_template, string  $content) : boolean

Write the rendered template output to cache

Parameters

\Smarty_Internal_Template $_template

template object

string $content

content to cache

Returns

boolean —

success

readCachedContent()

readCachedContent(\Smarty_Internal_Template  $_template) : string

Read cached template from cache

Parameters

\Smarty_Internal_Template $_template

template object

Returns

string —

content

clearAll()

clearAll(\Smarty  $smarty, integer  $exp_time = null) : integer

Empty cache

Parameters

\Smarty $smarty

Smarty object

integer $exp_time

expiration time (number of seconds, not timestamp)

Returns

integer —

number of cache files deleted

clear()

clear(\Smarty  $smarty, string  $resource_name, string  $cache_id, string  $compile_id, integer  $exp_time) : integer

Empty cache for a specific template

Parameters

\Smarty $smarty

Smarty object

string $resource_name

template name

string $cache_id

cache id

string $compile_id

compile id

integer $exp_time

expiration time (number of seconds, not timestamp)

Returns

integer —

number of cache files deleted

hasLock()

hasLock(\Smarty  $smarty, \Smarty_Template_Cached  $cached) : boolean

Check is cache is locked for this template

Parameters

\Smarty $smarty
\Smarty_Template_Cached $cached

Returns

boolean

acquireLock()

acquireLock(\Smarty  $smarty, \Smarty_Template_Cached  $cached) : boolean

Lock cache for this template

Parameters

\Smarty $smarty
\Smarty_Template_Cached $cached

Returns

boolean

releaseLock()

releaseLock(\Smarty  $smarty, \Smarty_Template_Cached  $cached) : boolean

Unlock cache for this template

Parameters

\Smarty $smarty
\Smarty_Template_Cached $cached

Returns

boolean

getCachedContent()

getCachedContent(\Smarty_Internal_Template  $_template) : null|string

Return cached content

Parameters

\Smarty_Internal_Template $_template

template object

Returns

null|string

locked()

locked(\Smarty  $smarty, \Smarty_Template_Cached  $cached) : boolean|null

Parameters

\Smarty $smarty
\Smarty_Template_Cached $cached

Returns

boolean|null

load()

load(\Smarty  $smarty, string  $type = null) : \Smarty_CacheResource

Load Cache Resource Handler

Parameters

\Smarty $smarty

Smarty object

string $type

name of the cache resource

Throws

\SmartyException

Returns

\Smarty_CacheResource

Cache Resource Handler

__construct()

__construct(\PDO  $pdo,   $table,   $database = null) 

Parameters

\PDO $pdo
$table
$database

fetch()

fetch(string  $id, string  $name, string|null  $cache_id = null, string|null  $compile_id = null, string  $content, integer  $mtime) : void

fetch cached content and its modification time from data source

Parameters

string $id

unique cache content identifier

string $name

template name

string|null $cache_id

cache id

string|null $compile_id

compile id

string $content

cached content

integer $mtime

cache modification timestamp (epoch)

fetchTimestamp()

fetchTimestamp(string  $id, string  $name, string  $cache_id, string  $compile_id) : integer|boolean

Fetch cached content's modification timestamp from data source {@internal implementing this method is optional.

Only implement it if modification times can be accessed faster than loading the complete cached content.}}

Parameters

string $id

unique cache content identifier

string $name

template name

string $cache_id

cache id

string $compile_id

compile id

Returns

integer|boolean —

timestamp (epoch) the template was modified, or false if not found

save()

save(string  $id, string  $name, string|null  $cache_id = null, string|null  $compile_id = null, integer|null  $exp_time, string  $content) : boolean

Save content to cache

Parameters

string $id

unique cache content identifier

string $name

template name

string|null $cache_id

cache id

string|null $compile_id

compile id

integer|null $exp_time

seconds till expiration time in seconds or null

string $content

content to cache

Returns

boolean —

success

delete()

delete(string|null  $name = null, string|null  $cache_id = null, string|null  $compile_id = null, integer|null|\-1  $exp_time = null) : integer

Delete content from cache

Parameters

string|null $name

template name

string|null $cache_id

cache id

string|null $compile_id

compile id

integer|null|\-1 $exp_time

seconds till expiration or null

Returns

integer —

number of deleted caches

fillStatementsWithTableName()

fillStatementsWithTableName() 

getFetchStatement()

getFetchStatement(  $columns,   $id,   $cache_id = null,   $compile_id = null) 

Parameters

$columns
$id
$cache_id
$compile_id

inputContent()

inputContent(  $content) 

Parameters

$content

outputContent()

outputContent(  $content) 

Parameters

$content

getTableName()

getTableName() : string

Gets the formatted table name

Returns

string