Lock cache for this template

@param Smarty                 $smarty Smarty object
@param Smarty_Template_Cached $cached cached object
330192
public function acquireLock(Smarty $smarty, Smarty_Template_Cached $cached)
    {
        $cached->is_locked = true;

        $id = $cached->filepath;
        $name = $cached->source->name . '.lock';
        $this->save($id, $name, null, null, $smarty->locking_timeout, '');
    }
27635
public function lock($key, $wouldBlock = false)
    {
        if (empty($key)) {
            return false;
        }
        $key = $this->getKey($key);

        if (
            isset($this->lockCache[$key])
            && $this->lockCache[$key] == Model::getInstance()->cache($this->useCache)->getInstance()->get($key)
        ) {
            return true;
        }

        if (Model::getInstance()->cache($this->useCache)->getInstance()->set(
            $key,
            Cml::$nowMicroTime,
            ['nx', 'ex' => $this->expire]
        )
        ) {
            $this->lockCache[$key] = (string)Cml::$nowMicroTime;
            return true;
        }

        //非堵塞模式
        if (!$wouldBlock) {
            return false;
        }

        //堵塞模式
        do {
            usleep(200);
        } while (!Model::getInstance()->cache($this->useCache)->getInstance()->set(
            $key,
            Cml::$nowMicroTime,
            ['nx', 'ex' => $this->expire]
        ));

        $this->lockCache[$key] = (string)Cml::$nowMicroTime;
        return true;
    }
1169833
protected function lockNestedSet($entityNode)
	{
		$class = is_string($entityNode) ? $entityNode : $entityNode->getNestedSetRepositoryClassName();

		$this->getEntityManager()
				->getRepository($class)
				->getNestedSetRepository()
				->lock();
	}
169777
public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached)
    {
        $id = $cached->lock_id;
        $name = $cached->source->name . '.lock';

        $mtime = $this->fetchTimestamp($id, $name, $cached->cache_id, $cached->compile_id);
        if ($mtime === null) {
            $this->fetch($id, $name, $cached->cache_id, $cached->compile_id, $content, $mtime);
        }
        return $mtime && ($t = time()) - $mtime < $smarty->locking_timeout;
    }
1029963
public static function get_cachelock_for_store(cache_store $store) {
        $instance = cache_config::instance();
        $lockconf = $instance->get_lock_for_store($store->my_name());
        $factory = cache_factory::instance();
        return $factory->create_lock_instance($lockconf);
    }
585997
public static function load(Smarty $smarty, $type = null)
    {
        if (!isset($type)) {
            $type = $smarty->caching_type;
        }

        // try smarty's cache
        if (isset($smarty->_cache['cacheresource_handlers'][$type])) {
            return $smarty->_cache['cacheresource_handlers'][$type];
        }

        // try registered resource
        if (isset($smarty->registered_cache_resources[$type])) {
            // do not cache these instances as they may vary from instance to instance
            return $smarty->_cache['cacheresource_handlers'][$type] = $smarty->registered_cache_resources[$type];
        }
        // try sysplugins dir
        if (isset(self::$sysplugins[$type])) {
            $cache_resource_class = 'Smarty_Internal_CacheResource_' . ucfirst($type);
            return $smarty->_cache['cacheresource_handlers'][$type] = new $cache_resource_class();
        }
        // try plugins dir
        $cache_resource_class = 'Smarty_CacheResource_' . ucfirst($type);
        if ($smarty->loadPlugin($cache_resource_class)) {
            return $smarty->_cache['cacheresource_handlers'][$type] = new $cache_resource_class();
        }
        // give up
        throw new SmartyException("Unable to load cache resource '{$type}'");
    }
385746
protected function updateCachedRequest($cached, $responseHeaders) {
    if (isset($responseHeaders['connection'])) {
      $hopByHop = array_merge(
        self::$HOP_BY_HOP,
        explode(',', $responseHeaders['connection'])
      );

      $endToEnd = array();
      foreach($hopByHop as $key) {
        if (isset($responseHeaders[$key])) {
          $endToEnd[$key] = $responseHeaders[$key];
        }
      }
      $cached->setResponseHeaders($endToEnd);
    }
  }
662070
public function writeCachedContent(Smarty_Internal_Template $_template, $content)
    {
        return $this->save(
            $_template->cached->filepath,
            $_template->source->name,
            $_template->cache_id,
            $_template->compile_id,
            $_template->properties['cache_lifetime'],
            $content
        );
    }
462950
public function setItem($cacheId, $content)
    {
        $cacheId = $this->normalizeKey($cacheId);

        try {
            return $this->cache->store($cacheId, serialize($content));
        } catch (ezcBaseException $ex) {
            return false;
        }
    }
705406
public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template)
    {
        $_source_file_path = str_replace(':', '.', $_template->source->filepath);
        $_cache_id = isset($_template->cache_id) ? preg_replace('![^\w\|]+!', '_', $_template->cache_id) : null;
        $_compile_id = isset($_template->compile_id) ? preg_replace('![^\w]+!', '_', $_template->compile_id) : null;
        $_filepath = $_template->source->uid;
        // if use_sub_dirs, break file into directories
        if ($_template->smarty->use_sub_dirs) {
            $_filepath = substr($_filepath, 0, 2) . DS . substr($_filepath, 2, 2) . DS . substr($_filepath, 4, 2) . DS .
                $_filepath;
        }
        $_compile_dir_sep = $_template->smarty->use_sub_dirs ? DS : '^';
        if (isset($_cache_id)) {
            $_cache_id = str_replace('|', $_compile_dir_sep, $_cache_id) . $_compile_dir_sep;
        } else {
            $_cache_id = '';
        }
        if (isset($_compile_id)) {
            $_compile_id = $_compile_id . $_compile_dir_sep;
        } else {
            $_compile_id = '';
        }
        $_cache_dir = $_template->smarty->getCacheDir();
        if ($_template->smarty->cache_locking) {
            // create locking file name
            // relative file name?
            if (!preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_cache_dir)) {
                $_lock_dir = rtrim(getcwd(), '/\\') . DS . $_cache_dir;
            } else {
                $_lock_dir = $_cache_dir;
            }
            $cached->lock_id = $_lock_dir . sha1($_cache_id . $_compile_id . $_template->source->uid) . '.lock';
        }
        $cached->filepath = $_cache_dir . $_cache_id . $_compile_id . $_filepath . '.' . basename($_source_file_path) .
            '.php';
        $cached->timestamp = $cached->exists = is_file($cached->filepath);
        if ($cached->exists) {
            $cached->timestamp = filemtime($cached->filepath);
        }
    }
177655
static function storeCache( $key, $templateFilepath )
    {
        if ( !eZTemplateTreeCache::isCacheEnabled() )
            return false;
        $templateCache =& eZTemplateTreeCache::cacheTable();
        $key = eZTemplateTreeCache::internalKey( $key );
        if ( !isset( $templateCache[$key] ) )
        {
            eZDebug::writeDebug( "Template cache for key '$key' does not exist, cannot store cache", __METHOD__ );
            return;
        }
        $cacheFileName = eZTemplateTreeCache::treeCacheFilename( $key, $templateFilepath );

        $cache =& $templateCache[$key];

        $php = new eZPHPCreator( eZTemplateTreeCache::cacheDirectory(), $cacheFileName );
        $php->addVariable( 'eZTemplateTreeCacheCodeDate', eZTemplateTreeCache::CODE_DATE );
        $php->addSpace();
        $php->addVariable( 'TemplateInfo', $cache['info'] );
        $php->addSpace();
        $php->addVariable( 'TemplateRoot', $cache['root'] );
        $php->store( true );
    }
979619
public function write(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template, $content)
    {
        if (!$_template->source->handler->recompiled) {
            if ($cached->handler->writeCachedContent($_template, $content)) {
                $cached->content = null;
                $cached->timestamp = time();
                $cached->exists = true;
                $cached->valid = true;
                $cached->cache_lifetime = $_template->cache_lifetime;
                $cached->processed = false;
                if ($_template->smarty->cache_locking) {
                    $cached->handler->releaseLock($_template->smarty, $cached);
                }

                return true;
            }
            $cached->content = null;
            $cached->timestamp = false;
            $cached->exists = false;
            $cached->valid = false;
            $cached->processed = false;
        }

        return false;
    }
1040143
public function writeCachedContent(Smarty_Internal_Template $_template, $content)
    {
        $this->addMetaTimestamp($content);

        return $this->write(array($_template->cached->filepath => $content), $_template->cache_lifetime);
    }
1232615
public function register_block($name, $callback, $cacheable = true, $cache_attrs = null)
    {
        if (isset($this->plugins[$name]) && $this->plugins[$name][0] !== self::SMARTY_BLOCK) {
            throw new Exception('Multiple plugins of different types can not share the same name');
        }
        $this->plugins[$name] = array(
            'type'     => self::SMARTY_BLOCK,
            'callback' => $callback
        );
    }
104891
public function populateTimestamp(Smarty_Template_Cached $cached)
    {
        $cached->timestamp = $cached->exists = is_file($cached->filepath);
        if ($cached->exists) {
            $cached->timestamp = filemtime($cached->filepath);
        }
    }
31154
public function lock($document, $lockMode)
    {
        $qb          = $this->dm->createQueryBuilder($this->class->name);
        $identifier  = $this->uow->getDocumentIdentifier($document);
        $lockMapping = $this->class->lockMetadata;

        $qb->update();
        $qb->setIdentifier($identifier);

        $qb->attr($lockMapping->name)->set($lockMode);
        $qb->getQuery()->execute();

        $lockMapping->setValue($document, $lockMode);
    }
743923
public function setLock(CacheKey $key, Lock $lock)
    {
        $this->locks[$key->hash] = $lock;
    }