libs/sysplugins/smarty_cacheresource.php Quellcode

smarty_cacheresource.php
gehe zur Dokumentation dieser Datei
1 <?php
16 abstract class Smarty_CacheResource
17 {
23  protected static $sysplugins = array(
24  'file' => 'smarty_internal_cacheresource_file.php',
25  );
26 
35  abstract public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template);
36 
44  abstract public function populateTimestamp(Smarty_Template_Cached $cached);
45 
54  abstract public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null);
55 
64  abstract public function writeCachedContent(Smarty_Internal_Template $_template, $content);
65 
73  public function getCachedContent(Smarty_Internal_Template $_template)
74  {
75  if ($_template->cached->handler->process($_template)) {
76  ob_start();
77  $_template->properties['unifunc']($_template);
78 
79  return ob_get_clean();
80  }
81 
82  return null;
83  }
84 
93  abstract public function clearAll(Smarty $smarty, $exp_time = null);
94 
106  abstract public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time);
107 
114  public function locked(Smarty $smarty, Smarty_Template_Cached $cached)
115  {
116  // theoretically locking_timeout should be checked against time_limit (max_execution_time)
117  $start = microtime(true);
118  $hadLock = null;
119  while ($this->hasLock($smarty, $cached)) {
120  $hadLock = true;
121  if (microtime(true) - $start > $smarty->locking_timeout) {
122  // abort waiting for lock release
123  return false;
124  }
125  sleep(1);
126  }
127 
128  return $hadLock;
129  }
130 
139  public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached)
140  {
141  // check if lock exists
142  return false;
143  }
144 
153  public function acquireLock(Smarty $smarty, Smarty_Template_Cached $cached)
154  {
155  // create lock
156  return true;
157  }
158 
167  public function releaseLock(Smarty $smarty, Smarty_Template_Cached $cached)
168  {
169  // release lock
170  return true;
171  }
172 
182  public static function load(Smarty $smarty, $type = null)
183  {
184  if (!isset($type)) {
185  $type = $smarty->caching_type;
186  }
187 
188  // try smarty's cache
189  if (isset($smarty->_cacheresource_handlers[$type])) {
190  return $smarty->_cacheresource_handlers[$type];
191  }
192 
193  // try registered resource
194  if (isset($smarty->registered_cache_resources[$type])) {
195  // do not cache these instances as they may vary from instance to instance
196  return $smarty->_cacheresource_handlers[$type] = $smarty->registered_cache_resources[$type];
197  }
198  // try sysplugins dir
199  if (isset(self::$sysplugins[$type])) {
200  $cache_resource_class = 'Smarty_Internal_CacheResource_' . ucfirst($type);
201  if (!class_exists($cache_resource_class, false)) {
202  require SMARTY_SYSPLUGINS_DIR . self::$sysplugins[$type];
203  }
204  return $smarty->_cacheresource_handlers[$type] = new $cache_resource_class();
205  }
206  // try plugins dir
207  $cache_resource_class = 'Smarty_CacheResource_' . ucfirst($type);
208  if ($smarty->loadPlugin($cache_resource_class)) {
209  return $smarty->_cacheresource_handlers[$type] = new $cache_resource_class();
210  }
211  // give up
212  throw new SmartyException("Unable to load cache resource '{$type}'");
213  }
214 
220  public static function invalidLoadedCache(Smarty $smarty)
221  {
222  foreach ($smarty->template_objects as $tpl) {
223  if (isset($tpl->cached)) {
224  $tpl->cached->valid = false;
225  $tpl->cached->processed = false;
226  }
227  }
228  }
229 }




Korrekturen, Hinweise und Ergänzungen

Bitte scheuen Sie sich nicht und melden Sie, was auf dieser Seite sachlich falsch oder irreführend ist, was ergänzt werden sollte, was fehlt usw. Dazu bitte oben aus dem Menü Seite den Eintrag Support Forum wählen. Es ist eine kostenlose Anmeldung erforderlich, um Anmerkungen zu posten. Unpassende Postings, Spam usw. werden kommentarlos entfernt.