コード例 #1
0
 public function getTree()
 {
     if (!$this->_tree) {
         $cache = new ExpirableConfigCache($this->cacheFile, $this->debug, $this->metaQuery->getLastTouched());
         $_watch = $this->startTiming('Checking whether the cache is fresh');
         $fresh = $cache->isFresh();
         $this->stopTiming($_watch);
         if (!$fresh) {
             $cs = new \Webfactory\Bundle\WfdMetaBundle\Util\CriticalSection();
             $cs->setLogger($this->logger);
             $_watch = $this->startTiming('Critical section');
             $self = $this;
             $cs->execute(__FILE__, function () use($self, $cache) {
                 if (!$cache->isFresh()) {
                     $self->debug("Building the tree");
                     $self->buildTreeCache($cache);
                     $self->debug("Finished building the tree");
                 } else {
                     $self->debug("Had to wait for the cache to be initialized by another process");
                 }
             });
             $this->stopTiming($_watch);
         }
         if (!$this->_tree) {
             $this->debug("Loading the cached tree");
             $_watch = $this->startTiming('Loading a cached tree');
             $this->_tree = (require $cache);
             $this->stopTiming($_watch);
             $this->debug("Finished loading the cached tree");
         }
         if ($this->eventDispatcher) {
             $this->eventDispatcher->dispatch('webfactory_navigation.tree_initialized', new TreeInitializedEvent($this->_tree));
         }
     }
     return $this->_tree;
 }
コード例 #2
0
 public function dumpIntoCache(ExpirableConfigCache $cache, $what)
 {
     $routeCollection = $this->getRouteCollection();
     $dumperClass = $this->getOption("{$what}_dumper_class");
     $dumper = new $dumperClass($routeCollection);
     $cache->write($dumper->dump(array('class' => $this->options["{$what}_cache_class"], 'base_class' => $this->getOption("{$what}_base_class"))), $routeCollection->getResources());
     $this->debug("{$dumperClass} dumped the RouteCollection.");
     /*
      * Weil wir jetzt schon eine initialisierte RouteCollection auf dieser
      * Klasse haben und noch in der critical section sind, sichern
      * wir schnell auch noch "das andere" matcher|generator-Ding,
      * das ebenfalls von der RouteCollection abhängt.
      */
     $this->createAndCache($what == 'matcher' ? 'generator' : 'matcher');
 }