Пример #1
0
 /**
  * Returns this collection and added tags
  *
  * @param boolean $deep
  * @return array
  */
 public function getCacheTags($deep = true)
 {
     $table = $this->getTable();
     if (!$table->hasTemplate(sfCacheTaggingToolkit::TEMPLATE_NAME)) {
         throw new sfConfigurationException(sprintf('Model "%s" has no "%s" templates', $table->getClassnameToReturn(), sfCacheTaggingToolkit::TEMPLATE_NAME));
     }
     $namespace = $this->getNamespace();
     $tagHandler = null;
     try {
         $taggingCache = $this->getTaggingCache();
         $tagHandler = $taggingCache->getContentTagHandler();
     } catch (sfCacheDisabledException $e) {
         $this->notifyApplicationLog($e);
         return array();
     }
     if ($this->count()) {
         foreach ($this as $object) {
             $tags = $object->getCacheTags($deep);
             $tagHandler->addContentTags($tags, $namespace);
         }
         $tagHandler->addContentTags($this->getCollectionTags(), $namespace);
     } else {
         /**
          * little hack, if collection is empty, emulate collection,
          * without any tags, but version should be staticaly
          * fixed (in day range)
          *
          * repeating calls with relative microtime always refresh collection tag
          * so, here is day-fixed value
          */
         $tagHandler->setContentTag(sfCacheTaggingToolkit::obtainCollectionName($table), sfCacheTaggingToolkit::generateVersion(strtotime('today')), $namespace);
     }
     $tagHandler->addContentTags($tagHandler->getContentTags($this->getNamespace(true)), $namespace);
     $tags = $tagHandler->getContentTags($namespace);
     $tagHandler->removeContentTags($namespace);
     return $tags;
 }
Пример #2
0
 /**
  * pre dql delete hook - remove object tags from tagger
  *
  * @param Doctrine_Event $event
  * @return null
  */
 public function preDqlDelete(Doctrine_Event $event)
 {
     $taggingCache = null;
     try {
         $taggingCache = $this->getTaggingCache();
     } catch (sfCacheException $e) {
         return;
     }
     $table = $event->getInvoker()->getTable();
     /* @var $q Doctrine_Query */
     $q = clone $event->getQuery();
     /**
      * This happens, when SoftDelete is declared before Cachetaggable
      */
     if (Doctrine_Query::UPDATE === $q->getType()) {
         $event->getQuery()->set($this->getOption('versionColumn'), sfCacheTaggingToolkit::generateVersion());
         $q->removeDqlQueryPart('set');
     }
     $params = $q->getParams();
     $params['set'] = array();
     $q->setParams($params);
     $objects = $q->select()->execute();
     $unitOfWork = new Doctrine_Connection_CachetaggableUnitOfWork($q->getConnection());
     foreach ($objects as $object) {
         $unitOfWork->collectDeletionsAndInvalidations($object);
         $taggingCache->deleteTags($unitOfWork->getDeletions());
         $taggingCache->invalidateTags($unitOfWork->getInvalidations());
     }
     unset($unitOfWork);
     $taggingCache->setTag(sfCacheTaggingToolkit::getBaseClassName($table->getClassnameToReturn()), sfCacheTaggingToolkit::generateVersion());
 }
 /**
  * Invalidate tags
  *
  * @param array $tags
  * @return null
  */
 public function invalidateTags(array $tags)
 {
     foreach ($tags as $name => $version) {
         $this->setTag($name, sfCacheTaggingToolkit::generateVersion());
     }
 }
Пример #4
0
 /**
  * Updates object version
  *
  * @return Doctrine_Recotd
  */
 public function updateObjectVersion()
 {
     return $this->assignObjectVersion(sfCacheTaggingToolkit::generateVersion());
 }