56 $cached->filepath = $_template->source->uid
57 .
'#' . $this->
sanitize($cached->source->name)
58 .
'#' . $this->
sanitize($cached->cache_id)
59 .
'#' . $this->
sanitize($cached->compile_id);
72 if (!$this->
fetch($cached->filepath, $cached->source->name, $cached->cache_id, $cached->compile_id, $content, $timestamp, $cached->source->uid)) {
75 $cached->content = $content;
76 $cached->timestamp = (int) $timestamp;
77 $cached->exists = $cached->timestamp;
90 $cached = $_template->cached;
92 $content = $cached->content ? $cached->content : null;
93 $timestamp = $cached->timestamp ? $cached->timestamp : null;
94 if ($content === null || !$timestamp) {
95 if (!$this->
fetch($_template->cached->filepath, $_template->source->name, $_template->cache_id, $_template->compile_id, $content, $timestamp, $_template->source->uid)) {
99 if (isset($content)) {
100 $_smarty_tpl = $_template;
101 eval(
"?>" . $content);
117 return $this->
write(array($_template->cached->filepath => $content), $_template->properties[
'cache_lifetime']);
133 if (!$this->
purge()) {
154 public function clear(
Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time)
156 $uid = $this->
getTemplateUid($smarty, $resource_name, $cache_id, $compile_id);
157 $cid = $uid .
'#' . $this->
sanitize($resource_name) .
'#' . $this->
sanitize($cache_id) .
'#' . $this->
sanitize($compile_id);
158 $this->
delete(array($cid));
159 $this->
invalidate($cid, $resource_name, $cache_id, $compile_id, $uid);
174 if (isset($resource_name)) {
175 $tpl =
new $smarty->template_class($resource_name, $smarty);
176 if (
$tpl->source->exists) {
177 $uid =
$tpl->source->uid;
181 if ($smarty->allow_ambiguous_resources) {
182 $_templateId =
$tpl->source->unique_resource .
$tpl->cache_id .
$tpl->compile_id;
184 $_templateId = $smarty->joined_template_dir .
'#' . $resource_name .
$tpl->cache_id .
$tpl->compile_id;
186 if (isset($_templateId[150])) {
187 $_templateId = sha1($_templateId);
189 unset($smarty->template_objects[$_templateId]);
203 $string = trim($string,
'|');
207 return preg_replace(
'#[^\w\|]+#S',
'_', $string);
222 protected function fetch($cid, $resource_name = null, $cache_id = null, $compile_id = null, &$content = null, &$timestamp = null, $resource_uid = null)
224 $t = $this->
read(array($cid));
225 $content = !empty($t[$cid]) ? $t[$cid] : null;
230 if ($invalidated > $timestamp) {
248 $mt = explode(
" ", microtime());
249 $ts = pack(
"NN", $mt[1], (
int) ($mt[0] * 100000000));
250 $content = $ts . $content;
261 $s = unpack(
"N", substr($content, 0, 4));
262 $m = unpack(
"N", substr($content, 4, 4));
263 $content = substr($content, 8);
264 return $s[1] + ($m[1] / 100000000);
277 protected function invalidate($cid = null, $resource_name = null, $cache_id = null, $compile_id = null, $resource_uid = null)
279 $now = microtime(
true);
282 if (!$resource_name && !$cache_id && !$compile_id) {
286 else if ($resource_name && !$cache_id && !$compile_id) {
287 $key =
'IVK#TEMPLATE#' . $resource_uid .
'#' . $this->
sanitize($resource_name);
290 else if (!$resource_name && $cache_id && !$compile_id) {
291 $key =
'IVK#CACHE#' . $this->
sanitize($cache_id);
294 else if (!$resource_name && !$cache_id && $compile_id) {
295 $key =
'IVK#COMPILE#' . $this->
sanitize($compile_id);
299 $key =
'IVK#CID#' . $cid;
301 $this->
write(array($key => $now));
317 if (
false && !$cid) {
321 if (!($_cid = $this->
listInvalidationKeys($cid, $resource_name, $cache_id, $compile_id, $resource_uid))) {
326 if (!($values = $this->
read($_cid))) {
330 $values = array_map(
'floatval', $values);
347 protected function listInvalidationKeys($cid, $resource_name = null, $cache_id = null, $compile_id = null, $resource_uid = null)
349 $t = array(
'IVK#ALL');
350 $_name = $_compile =
'#';
351 if ($resource_name) {
352 $_name .= $resource_uid .
'#' . $this->
sanitize($resource_name);
353 $t[] =
'IVK#TEMPLATE' . $_name;
356 $_compile .= $this->
sanitize($compile_id);
357 $t[] =
'IVK#COMPILE' . $_compile;
361 $cid = trim($cache_id,
'|');
368 $i = strpos($cid,
'|',
$i);
371 $t[] =
'IVK#CACHE#' . $cid;
372 $t[] =
'IVK#CID' . $_name . $cid . $_compile;
373 $t[] =
'IVK#CID' . $_name . $_compile;
376 $part = substr($cid, 0,
$i);
378 $t[] =
'IVK#CACHE#' . $part;
379 $t[] =
'IVK#CID' . $_name . $part . $_compile;
395 $key =
'LOCK#' . $cached->filepath;
397 return $data && time() -
$data[$key] < $smarty->locking_timeout;
408 $cached->is_locked =
true;
409 $key =
'LOCK#' . $cached->filepath;
410 $this->
write(array($key => time()), $smarty->locking_timeout);
421 $cached->is_locked =
false;
422 $key =
'LOCK#' . $cached->filepath;
423 $this->
delete(array($key));
432 protected abstract function read(array $keys);
441 protected abstract function write(array $keys, $expire=null);
449 protected abstract function delete(array $keys);
write(array $keys, $expire=null)
Save values for a set of keys to cache.
foreach(array('date1', 'date2', 'type', 'renewals', 'width') as $item) $data
process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached=null)
Read the cached template and process the header.
addMetaTimestamp(&$content)
Add current microtime to the beginning of $cache_content.
read(array $keys)
Read values for a set of keys from cache.
writeCachedContent(Smarty_Internal_Template $_template, $content)
Write the rendered template output to cache.
if(!empty($_GET['id'])) if(isset($_POST['form_name'], $_POST['form_subject'], $_POST['form_text'], $_POST['form_lang'])&&empty($_GET['id'])) if(empty($_GET['id'])) $tpl
Smarty plugin to format text blocks.
listInvalidationKeys($cid, $resource_name=null, $cache_id=null, $compile_id=null, $resource_uid=null)
Translate a CacheID into the list of applicable InvalidationKeys.
getLatestInvalidationTimestamp($cid, $resource_name=null, $cache_id=null, $compile_id=null, $resource_uid=null)
Determine the latest timestamp known to the invalidation chain.
fetch($cid, $resource_name=null, $cache_id=null, $compile_id=null, &$content=null, &$timestamp=null, $resource_uid=null)
Fetch and prepare a cache object.
acquireLock(Smarty $smarty, Smarty_Template_Cached $cached)
Lock cache for this template.
releaseLock(Smarty $smarty, Smarty_Template_Cached $cached)
Unlock cache for this template.
clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time)
Empty cache for a specific template.
populateTimestamp(Smarty_Template_Cached $cached)
populate Cached Object with timestamp and exists from Resource
populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template)
populate Cached Object with meta data from Resource
getTemplateUid(Smarty $smarty, $resource_name, $cache_id, $compile_id)
Get template's unique ID.
getMetaTimestamp(&$content)
Extract the timestamp the $content was cached.
hasLock(Smarty $smarty, Smarty_Template_Cached $cached)
Check is cache is locked for this template.
clearAll(Smarty $smarty, $exp_time=null)
Empty cache.
purge()
Remove all values from cache.
invalidate($cid=null, $resource_name=null, $cache_id=null, $compile_id=null, $resource_uid=null)
Invalidate CacheID.
sanitize($string)
Sanitize CacheID components.