extends |
Smarty_CacheResource_Custom |
---|
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'));
Methods | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
public
|
__construct(PDO $pdo, string $table, string $database = null)
Constructor
Constructor Parameters
Throws
|
# | ||||||||||||
protected
|
fillStatementsWithTableName(): $this
Fills the table name into the statements.
Fills the table name into the statements. ReturnsCurrent Instance |
# | ||||||||||||
protected
|
getFetchStatement(
string $columns,
string $id,
string|null $cache_id = null,
string|null $compile_id = null,
): PDOStatement
Gets the fetch statement, depending on what you specify
Gets the fetch statement, depending on what you specify Parameters
|
# | ||||||||||||
protected
|
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
fetch cached content and its modification time from data source Parameters
Implements |
# | ||||||||||||
protected
|
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
Save content to cache Parameters
Returnssuccess Implements |
# | ||||||||||||
protected
|
inputContent(string $content): string
Encodes the content before saving to database
Encodes the content before saving to database Returns$content Overriden by |
# | ||||||||||||
protected
|
outputContent(string $content): string
Decodes the content before saving to database
Decodes the content before saving to database Returns$content Overriden by |
# | ||||||||||||
protected
|
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
Delete content from cache Parameters
Returnsnumber of deleted caches Implements |
# | ||||||||||||
protected
|
getTableName(): string
Gets the formatted table name
Gets the formatted table name |
# |
Methods inherited from Smarty_CacheResource_Custom |
---|
fetchTimestamp(), populate(), populateTimestamp(), process(), writeCachedContent(), readCachedContent(), clearAll(), clear(), hasLock(), acquireLock(), releaseLock() |
Methods inherited from Smarty_CacheResource |
---|
getCachedContent(), locked(), load() |
Properties | |||
---|---|---|---|
protected
|
string[]
|
$fetchStatements = [
'default' => 'SELECT %2$s
FROM %1$s
WHERE 1
AND id = :id
AND cache_id IS NULL
AND compile_id IS NULL',
'withCacheId' => 'SELECT %2$s
FROM %1$s
WHERE 1
AND id = :id
AND cache_id = :cache_id
AND compile_id IS NULL',
'withCompileId' => 'SELECT %2$s
FROM %1$s
WHERE 1
AND id = :id
AND compile_id = :compile_id
AND cache_id IS NULL',
'withCacheIdAndCompileId' => 'SELECT %2$s
FROM %1$s
WHERE 1
AND id = :id
AND cache_id = :cache_id
AND compile_id = :compile_id',
]
|
# |
protected
|
string
|
$insertStatement = 'INSERT INTO %s
SET id = :id,
name = :name,
cache_id = :cache_id,
compile_id = :compile_id,
modified = CURRENT_TIMESTAMP,
expire = DATE_ADD(CURRENT_TIMESTAMP, INTERVAL :expire SECOND),
content = :content
ON DUPLICATE KEY UPDATE
name = :name,
cache_id = :cache_id,
compile_id = :compile_id,
modified = CURRENT_TIMESTAMP,
expire = DATE_ADD(CURRENT_TIMESTAMP, INTERVAL :expire SECOND),
content = :content'
|
# |
protected
|
string
|
$deleteStatement = 'DELETE FROM %1$s WHERE %2$s'
|
# |
protected
|
string
|
$truncateStatement = 'TRUNCATE TABLE %s'
|
# |
protected
|
string
|
$fetchColumns = 'modified, content'
|
# |
protected
|
string
|
$fetchTimestampColumns = 'modified'
|
# |
protected
|
PDO
|
$pdo
|
# |
protected
|
|
$table
|
# |
protected
|
null
|
$database
|
# |
Properties inherited from Smarty_CacheResource |
---|
$sysplugins |