Functions for t3lib cache
Jump to navigation
Jump to search
This is the cache-implementation for the new sub-Core API t3lib_cache.
warning - Message
You're welcome to help, but you need to log-in into the wiki
Hash Functions
these 2 functions are a copy from t3lib_page and t3lib_befunc
/**
* Returns string value stored for the hash string in the table "cache_hash"
* Can be used to retrieved a cached value
* Can be used from your frontend plugins if you like. It is also used to store the parsed TypoScript template structures. You can call it directly like t3lib_pageSelect::getHash()
*
* @param string The hash-string which was used to store the data value
* @param integer Allowed expiretime in seconds. Basically a record is selected only if it is not older than this value in seconds. If expTime is not set, the hashed value will never expire.
* @return string The "content" field of the "cache_hash" table row.
* @see tslib_TStemplate::start(), storeHash()
*/
public function getHash($hash,$expTime=0) {
// if expTime is not set, the hash will never expire
$expTime = intval($expTime);
if ($expTime) {
$whereAdd = ' AND tstamp > '.(time()-$expTime);
}
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('content', 'cache_hash', 'hash='.$GLOBALS['TYPO3_DB']->fullQuoteStr($hash, 'cache_hash').$whereAdd);
$row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
$GLOBALS['TYPO3_DB']->sql_free_result($res);
if ($row) {
return $row['content'];
}
}
/**
* Stores a string value in the cache_hash table identified by $hash.
* Can be used from your frontend plugins if you like. You can call it directly like t3lib_pageSelect::storeHash()
*
* @param string 32 bit hash string (eg. a md5 hash of a serialized array identifying the data being stored)
* @param string The data string. If you want to store an array, then just serialize it first.
* @param string $ident is just a textual identification in order to inform about the content! May be 20 characters long.
* @return void
* @see tslib_TStemplate::start(), getHash()
*/
public function storeHash($hash,$data,$ident) {
$insertFields = array(
'hash' => $hash,
'content' => $data,
'ident' => $ident,
'tstamp' => time()
);
$GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_hash', 'hash='.$GLOBALS['TYPO3_DB']->fullQuoteStr($hash, 'cache_hash'));
$GLOBALS['TYPO3_DB']->exec_INSERTquery('cache_hash', $insertFields);
}
delete / add / update cache
public function clearPageCache($pid,$cHash=false) {
if($pid === false) {
$where = '1';
} else {
if(is_array($pid)) {
$where = 'page_id IN ('.implode(',', $pid).')';
} else {
$where = 'page_id = '.$pid;
}
}
$addWhere = $cHash ? ' and cHash = "'.$cHash.'"' : '';
//execute delete queries
$GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_pages', $where.$addWhere);
$GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_pagesection', $where.$addWhere);
}