123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- <?php
- abstract class Smarty_CacheResource
- {
-
- protected static $sysplugins = array('file' => 'smarty_internal_cacheresource_file.php',);
-
- abstract public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template);
-
- abstract public function populateTimestamp(Smarty_Template_Cached $cached);
-
- abstract public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null,
- $update = false);
-
- abstract public function writeCachedContent(Smarty_Internal_Template $_template, $content);
-
- abstract function readCachedContent(Smarty_Internal_Template $_template);
-
- public function getCachedContent(Smarty_Internal_Template $_template)
- {
- if ($_template->cached->handler->process($_template)) {
- ob_start();
- $unifunc = $_template->cached->unifunc;
- $unifunc($_template);
- return ob_get_clean();
- }
- return null;
- }
-
- abstract public function clearAll(Smarty $smarty, $exp_time = null);
-
- abstract public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time);
-
- public function locked(Smarty $smarty, Smarty_Template_Cached $cached)
- {
-
- $start = microtime(true);
- $hadLock = null;
- while ($this->hasLock($smarty, $cached)) {
- $hadLock = true;
- if (microtime(true) - $start > $smarty->locking_timeout) {
-
- return false;
- }
- sleep(1);
- }
- return $hadLock;
- }
-
- public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached)
- {
-
- return false;
- }
-
- public function acquireLock(Smarty $smarty, Smarty_Template_Cached $cached)
- {
-
- return true;
- }
-
- public function releaseLock(Smarty $smarty, Smarty_Template_Cached $cached)
- {
-
- return true;
- }
-
- public static function load(Smarty $smarty, $type = null)
- {
- if (!isset($type)) {
- $type = $smarty->caching_type;
- }
-
- if (isset($smarty->_cache[ 'cacheresource_handlers' ][ $type ])) {
- return $smarty->_cache[ 'cacheresource_handlers' ][ $type ];
- }
-
- if (isset($smarty->registered_cache_resources[ $type ])) {
-
- return $smarty->_cache[ 'cacheresource_handlers' ][ $type ] = $smarty->registered_cache_resources[ $type ];
- }
-
- if (isset(self::$sysplugins[ $type ])) {
- $cache_resource_class = 'Smarty_Internal_CacheResource_' . ucfirst($type);
- return $smarty->_cache[ 'cacheresource_handlers' ][ $type ] = new $cache_resource_class();
- }
-
- $cache_resource_class = 'Smarty_CacheResource_' . ucfirst($type);
- if ($smarty->loadPlugin($cache_resource_class)) {
- return $smarty->_cache[ 'cacheresource_handlers' ][ $type ] = new $cache_resource_class();
- }
-
- throw new SmartyException("Unable to load cache resource '{$type}'");
- }
- }
|