PEEL Shopping
Open source ecommerce : PEEL Shopping
smarty_cacheresource_custom.php
Go to the documentation of this file.
1 <?php
17 
29  protected abstract function fetch($id, $name, $cache_id, $compile_id, &$content, &$mtime);
30 
43  protected function fetchTimestamp($id, $name, $cache_id, $compile_id)
44  {
45  return null;
46  }
47 
59  protected abstract function save($id, $name, $cache_id, $compile_id, $exp_time, $content);
60 
70  protected abstract function delete($name, $cache_id, $compile_id, $exp_time);
71 
79  public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template)
80  {
81  $_cache_id = isset($cached->cache_id) ? preg_replace('![^\w\|]+!', '_', $cached->cache_id) : null;
82  $_compile_id = isset($cached->compile_id) ? preg_replace('![^\w\|]+!', '_', $cached->compile_id) : null;
83 
84  $cached->filepath = sha1($cached->source->filepath . $_cache_id . $_compile_id);
85  $this->populateTimestamp($cached);
86  }
87 
94  public function populateTimestamp(Smarty_Template_Cached $cached)
95  {
96  $mtime = $this->fetchTimestamp($cached->filepath, $cached->source->name, $cached->cache_id, $cached->compile_id);
97  if ($mtime !== null) {
98  $cached->timestamp = $mtime;
99  $cached->exists = !!$cached->timestamp;
100  return;
101  }
102  $timestamp = null;
103  $this->fetch($cached->filepath, $cached->source->name, $cached->cache_id, $cached->compile_id, $cached->content, $timestamp);
104  $cached->timestamp = isset($timestamp) ? $timestamp : false;
105  $cached->exists = !!$cached->timestamp;
106  }
107 
115  public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached=null)
116  {
117  if (!$cached) {
118  $cached = $_template->cached;
119  }
120  $content = $cached->content ? $cached->content : null;
121  $timestamp = $cached->timestamp ? $cached->timestamp : null;
122  if ($content === null || !$timestamp) {
123  $this->fetch(
124  $_template->cached->filepath,
125  $_template->source->name,
126  $_template->cache_id,
127  $_template->compile_id,
128  $content,
129  $timestamp
130  );
131  }
132  if (isset($content)) {
133  $_smarty_tpl = $_template;
134  eval("?>" . $content);
135  return true;
136  }
137  return false;
138  }
139 
147  public function writeCachedContent(Smarty_Internal_Template $_template, $content)
148  {
149  return $this->save(
150  $_template->cached->filepath,
151  $_template->source->name,
152  $_template->cache_id,
153  $_template->compile_id,
154  $_template->properties['cache_lifetime'],
155  $content
156  );
157  }
158 
166  public function clearAll(Smarty $smarty, $exp_time=null)
167  {
168  $this->cache = array();
169  return $this->delete(null, null, null, $exp_time);
170  }
171 
182  public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time)
183  {
184  $this->cache = array();
185  return $this->delete($resource_name, $cache_id, $compile_id, $exp_time);
186  }
187 
195  public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached)
196  {
197  $id = $cached->filepath;
198  $name = $cached->source->name . '.lock';
199 
200  $mtime = $this->fetchTimestamp($id, $name, null, null);
201  if ($mtime === null) {
202  $this->fetch($id, $name, null, null, $content, $mtime);
203  }
204 
205  return $mtime && time() - $mtime < $smarty->locking_timeout;
206  }
207 
214  public function acquireLock(Smarty $smarty, Smarty_Template_Cached $cached)
215  {
216  $cached->is_locked = true;
217 
218  $id = $cached->filepath;
219  $name = $cached->source->name . '.lock';
220  $this->save($id, $name, null, null, $smarty->locking_timeout, '');
221  }
222 
229  public function releaseLock(Smarty $smarty, Smarty_Template_Cached $cached)
230  {
231  $cached->is_locked = false;
232 
233  $name = $cached->source->name . '.lock';
234  $this->delete($name, null, null, null);
235  }
236 }
237 ?>
clearAll(Smarty $smarty, $exp_time=null)
Empty cache.
fetch($id, $name, $cache_id, $compile_id, &$content, &$mtime)
fetch cached content and its modification time from data source
releaseLock(Smarty $smarty, Smarty_Template_Cached $cached)
Unlock cache for this template.
acquireLock(Smarty $smarty, Smarty_Template_Cached $cached)
Lock cache for this template.
hasLock(Smarty $smarty, Smarty_Template_Cached $cached)
Check is cache is locked for this template.
Smarty plugin to format text blocks.
process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached=null)
Read the cached template and process the header.
populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template)
populate Cached Object with meta data from Resource
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
fetchTimestamp($id, $name, $cache_id, $compile_id)
Fetch cached content's modification timestamp from data source.
$id
Definition: articles.php:22
save($id, $name, $cache_id, $compile_id, $exp_time, $content)
Save content to cache.
writeCachedContent(Smarty_Internal_Template $_template, $content)
Write the rendered template output to cache.

This documentation for Open ecommerce PEEL Shopping and PEEL.fr has been generated by Doxygen on Thu Oct 15 2015 14:41:16 - Peel ecommerce is a product of Agence web Advisto SAS. All rights reserved.