From c019430a29863490b330e57c296ea6f12556bfcc Mon Sep 17 00:00:00 2001 From: AlexeyDsov Date: Tue, 3 Jul 2012 13:13:31 +0400 Subject: [PATCH 1/2] Introducing Uncachers --- core/Cache/Cache.class.php | 8 ++ core/DB/DB.class.php | 40 +++++++- global.inc.php.tpl | 1 + main/DAOs/BaseDAO.class.php | 6 +- main/DAOs/GenericDAO.class.php | 52 +++++++++-- main/DAOs/Uncachers/UncacherBase.class.php | 25 +++++ .../Uncachers/UncacherBaseDaoWorker.class.php | 80 ++++++++++++++++ .../UncacherCacheDaoWorkerLists.class.php | 77 ++++++++++++++++ .../UncacherCommonDaoWorker.class.php | 29 ++++++ .../Uncachers/UncacherGenericDAO.class.php | 77 ++++++++++++++++ .../Uncachers/UncacherNullDaoWorker.class.php | 36 ++++++++ .../UncacherSmartDaoWorkerLists.class.php | 92 +++++++++++++++++++ .../UncacherTaggableDaoWorker.class.php | 83 +++++++++++++++++ .../UncacherVoodoDaoWorkerLists.class.php | 76 +++++++++++++++ main/DAOs/Uncachers/UncachersPool.class.php | 71 ++++++++++++++ main/DAOs/Workers/BaseDaoWorker.class.php | 32 +++++-- main/DAOs/Workers/CacheDaoWorker.class.php | 11 +-- main/DAOs/Workers/CommonDaoWorker.class.php | 24 +++-- .../Workers/DalayedDropDaoWorker.class.php | 10 +- main/DAOs/Workers/NullDaoWorker.class.php | 9 +- main/DAOs/Workers/SmartDaoWorker.class.php | 24 +---- main/DAOs/Workers/VoodooDaoWorker.class.php | 9 +- 22 files changed, 814 insertions(+), 58 deletions(-) create mode 100644 main/DAOs/Uncachers/UncacherBase.class.php create mode 100644 main/DAOs/Uncachers/UncacherBaseDaoWorker.class.php create mode 100644 main/DAOs/Uncachers/UncacherCacheDaoWorkerLists.class.php create mode 100644 main/DAOs/Uncachers/UncacherCommonDaoWorker.class.php create mode 100644 main/DAOs/Uncachers/UncacherGenericDAO.class.php create mode 100644 main/DAOs/Uncachers/UncacherNullDaoWorker.class.php create mode 100644 main/DAOs/Uncachers/UncacherSmartDaoWorkerLists.class.php create mode 100644 main/DAOs/Uncachers/UncacherTaggableDaoWorker.class.php create mode 100644 main/DAOs/Uncachers/UncacherVoodoDaoWorkerLists.class.php create mode 100644 main/DAOs/Uncachers/UncachersPool.class.php diff --git a/core/Cache/Cache.class.php b/core/Cache/Cache.class.php index a863d19b1d..67487e4d58 100644 --- a/core/Cache/Cache.class.php +++ b/core/Cache/Cache.class.php @@ -58,6 +58,14 @@ public static function me() self::$peer = $peer; } + /** + * @return CachePeer + */ + public static function getPeer() + { + return self::$peer; + } + /* void */ public static function setDefaultWorker($worker) { Assert::classExists($worker); diff --git a/core/DB/DB.class.php b/core/DB/DB.class.php index 2bbf12992c..178169b3d5 100644 --- a/core/DB/DB.class.php +++ b/core/DB/DB.class.php @@ -42,6 +42,11 @@ abstract class DB private $queue = array(); private $toQueue = false; + /** + * @var UncachersPool + */ + private $uncacher = null; + private $outOfTransactionCachePeer = null; abstract public function connect(); abstract public function disconnect(); @@ -130,6 +135,9 @@ public function begin( $this->transaction = true; + $this->outOfTransactionCachePeer = Cache::getPeer(); + Cache::setPeer(new RuntimeMemory()); + return $this; } @@ -146,6 +154,9 @@ public function commit() $this->transaction = false; $this->savepointList = array(); + Cache::setPeer($this->outOfTransactionCachePeer); + $this->triggerUncacher(); + return $this; } @@ -162,6 +173,9 @@ public function rollback() $this->transaction = false; $this->savepointList = array(); + Cache::setPeer($this->outOfTransactionCachePeer); + $this->triggerUncacher(); + return $this; } @@ -401,6 +415,14 @@ public function setEncoding($encoding) return $this; } + public function registerUncacher(UncacherBase $uncacher) + { + $uncacher->uncache(); + if ($this->inTransaction()) { + $this->getUncacher()->merge($uncacher); + } + } + /** * @param string $savepointName * @return DB @@ -436,5 +458,21 @@ private function assertSavePointName($savepointName) { Assert::isEqual(1, preg_match('~^[A-Za-z][A-Za-z0-9]*$~iu', $savepointName)); } + + /** + * @return UncachersPool + */ + private function getUncacher() + { + return $this->uncacher = $this->uncacher ?: UncachersPool::create(); + } + + private function triggerUncacher() + { + if ($this->uncacher) { + $this->uncacher->uncache(); + $this->uncacher = null; + } + } } -?> \ No newline at end of file +?> diff --git a/global.inc.php.tpl b/global.inc.php.tpl index ebec12f051..efad9a5c6e 100644 --- a/global.inc.php.tpl +++ b/global.inc.php.tpl @@ -115,6 +115,7 @@ .ONPHP_MAIN_PATH.'DAOs' .PATH_SEPARATOR .ONPHP_MAIN_PATH.'DAOs'.DIRECTORY_SEPARATOR.'Handlers'.PATH_SEPARATOR .ONPHP_MAIN_PATH.'DAOs'.DIRECTORY_SEPARATOR.'Workers'.PATH_SEPARATOR + .ONPHP_MAIN_PATH.'DAOs'.DIRECTORY_SEPARATOR.'Uncachers'.PATH_SEPARATOR .ONPHP_MAIN_PATH.'Flow' .PATH_SEPARATOR .ONPHP_MAIN_PATH.'SPL' .PATH_SEPARATOR diff --git a/main/DAOs/BaseDAO.class.php b/main/DAOs/BaseDAO.class.php index 8ddbeb4cef..4770358622 100644 --- a/main/DAOs/BaseDAO.class.php +++ b/main/DAOs/BaseDAO.class.php @@ -51,8 +51,12 @@ public function dropByIds(array $ids); /// uncachers //@{ public function uncacheById($id); + /** + * @return UncacherBase + */ + public function getUncacherById($id); public function uncacheByIds($ids); public function uncacheLists(); //@} } -?> \ No newline at end of file +?> diff --git a/main/DAOs/GenericDAO.class.php b/main/DAOs/GenericDAO.class.php index ab0cd44dd5..569e7718c1 100644 --- a/main/DAOs/GenericDAO.class.php +++ b/main/DAOs/GenericDAO.class.php @@ -301,17 +301,32 @@ public function dropByIds(array $ids) public function uncacheById($id) { - unset($this->identityMap[$id]); - - return Cache::worker($this)->uncacheById($id); + return $this->getUncacherById($id)->uncache(); + } + + /** + * @return UncachersPool + */ + public function getUncacherById($id) + { + return UncacherGenericDAO::create( + $this, + $id, + Cache::worker($this)->getUncacherById($id) + ); } public function uncacheByIds($ids) { + if (empty($ids)) + return; + + $uncacher = $this->getUncacherById(array_shift($ids)); + foreach ($ids as $id) - unset($this->identityMap[$id]); + $uncacher->merge($this->getUncacherById($id)); - return Cache::worker($this)->uncacheByIds($ids); + return $uncacher->uncache(); } public function uncacheLists() @@ -339,6 +354,11 @@ public function dropObjectIdentityMapById($id) return $this; } + public function registerWorkerUncacher(UncacherBase $uncacher) + { + DBPool::getByDao($this)->registerUncacher($uncacher); + } + protected function inject( InsertOrUpdateQuery $query, Identifiable $object @@ -362,9 +382,17 @@ protected function doInject( $db = DBPool::getByDao($this); if (!$db->isQueueActive()) { + $preUncacher = is_scalar($object->getId()) + ? $this->getUncacherById($object->getId()) + : null; + $count = $db->queryCount($query); - $this->uncacheById($object->getId()); + $uncacher = $this->getUncacherById($object->getId()); + if ($preUncacher) { + $uncacher->merge($uncacher); + } + $uncacher->uncache(); if ($count !== 1) throw new WrongStateException( @@ -372,9 +400,17 @@ protected function doInject( .$query->toDialectString($db->getDialect()) ); } else { + $preUncacher = is_scalar($object->getId()) + ? $this->getUncacherById($object->getId()) + : null; + $db->queryNull($query); - $this->uncacheById($object->getId()); + $uncacher = $this->getUncacherById($object->getId()); + if ($preUncacher) { + $uncacher->merge($uncacher); + } + $uncacher->uncache(); } // clean out Identifier, if any @@ -403,4 +439,4 @@ private function addObjectListToMap($list) return $list; } } -?> \ No newline at end of file +?> diff --git a/main/DAOs/Uncachers/UncacherBase.class.php b/main/DAOs/Uncachers/UncacherBase.class.php new file mode 100644 index 0000000000..9cc6df3270 --- /dev/null +++ b/main/DAOs/Uncachers/UncacherBase.class.php @@ -0,0 +1,25 @@ + \ No newline at end of file diff --git a/main/DAOs/Uncachers/UncacherBaseDaoWorker.class.php b/main/DAOs/Uncachers/UncacherBaseDaoWorker.class.php new file mode 100644 index 0000000000..37f1e296d7 --- /dev/null +++ b/main/DAOs/Uncachers/UncacherBaseDaoWorker.class.php @@ -0,0 +1,80 @@ +classNameMap[$className] = array($idKey); + } + + public function getClassNameMap() + { + return $this->classNameMap; + } + + /** + * @param $uncacher UncacherNullDaoWorker same as self class + * @return BaseUncacher (this) + */ + public function merge(UncacherBase $uncacher) + { + Assert::isInstance($uncacher, get_class($this)); + return $this->mergeSelf($uncacher); + } + + public function uncache() + { + foreach ($this->classNameMap as $className => $idKeys) { + foreach ($idKeys as $key) { + $this->uncacheClassName($className, $idKeys); + } + } + } + + protected function uncacheClassName($className, $idKeys) { + foreach ($idKeys as $key) + Cache::me()->mark($className)->delete($key); + } + + /** + * @param UncacherBaseDaoWorker $uncacher + * @return UncacherBaseDaoWorker + */ + private function mergeSelf(UncacherBaseDaoWorker $uncacher) + { + foreach ($uncacher->getClassNameMap() as $className => $idKeys) { + if (isset($this->classNameMap[$className])) { + $this->classNameMap[$className] = ArrayUtils::mergeUnique( + $this->classNameMap[$className], + $idKeys + ); + } else { + $this->classNameMap[$className] = $idKeys; + } + } + return $this; + } + } +?> \ No newline at end of file diff --git a/main/DAOs/Uncachers/UncacherCacheDaoWorkerLists.class.php b/main/DAOs/Uncachers/UncacherCacheDaoWorkerLists.class.php new file mode 100644 index 0000000000..53816600f2 --- /dev/null +++ b/main/DAOs/Uncachers/UncacherCacheDaoWorkerLists.class.php @@ -0,0 +1,77 @@ +classNameList[$className] = $className; + } + + public function getClassNameList() + { + return $this->classNameList; + } + + /** + * @param $uncacher UncacherCacheDaoWorkerLists same as self class + * @return BaseUncacher (this) + */ + public function merge(UncacherBase $uncacher) + { + Assert::isInstance($uncacher, get_class($this)); + return $this->mergeSelf($uncacher); + } + + public function uncache() + { + foreach ($this->classNameList as $className) { + $this->uncacheClassName($className); + } + } + + private function uncacheClassName($className) + { + if ( + !Cache::me()-> + mark($className)-> + increment($className, 1) + ) + Cache::me()->mark($className)->delete($className); + } + + /** + * @param UncacherCacheDaoWorkerLists $uncacher + * @return UncacherCacheDaoWorkerLists + */ + private function mergeSelf(UncacherCacheDaoWorkerLists $uncacher) + { + foreach ($uncacher->getClassNameList() as $className) { + if (!isset($this->classNameList[$className])) + $this->classNameList[$className] = $className; + } + return $this; + } + } +?> \ No newline at end of file diff --git a/main/DAOs/Uncachers/UncacherCommonDaoWorker.class.php b/main/DAOs/Uncachers/UncacherCommonDaoWorker.class.php new file mode 100644 index 0000000000..193b1b80a4 --- /dev/null +++ b/main/DAOs/Uncachers/UncacherCommonDaoWorker.class.php @@ -0,0 +1,29 @@ +uncacheLists(); + parent::uncacheClassName($className, $idKeys); + } + } +?> \ No newline at end of file diff --git a/main/DAOs/Uncachers/UncacherGenericDAO.class.php b/main/DAOs/Uncachers/UncacherGenericDAO.class.php new file mode 100644 index 0000000000..6b1bd7912a --- /dev/null +++ b/main/DAOs/Uncachers/UncacherGenericDAO.class.php @@ -0,0 +1,77 @@ +daoMap[get_class($dao)] = array(array($id), $workerUncacher); + } + + public function getDaoMap() + { + return $this->daoMap; + } + + /** + * @param $uncacher UncacherGenericDAO same as self class + * @return UncacherBase (this) + */ + public function merge(UncacherBase $uncacher) + { + Assert::isInstance($uncacher, 'UncacherGenericDAO'); + return $this->mergeSelf($uncacher); + } + + public function uncache() + { + foreach ($this->daoMap as $daoClass => $uncacheData) { + $dao = GenericDAO::getInstance($daoClass); + /* @var $dao GenericDAO */ + list($dropIdentityIds, $workerUncacher) = $uncacheData; + /* @var $workerUncacher UncacherBase */ + + foreach ($dropIdentityIds as $id) + $dao->dropObjectIdentityMapById($id); + + $dao->registerWorkerUncacher($workerUncacher); + } + } + + private function mergeSelf(UncacherGenericDAO $uncacher) { + foreach ($uncacher->getDaoMap() as $daoClass => $daoMap) { + if (isset($this->daoMap[$daoClass])) { + //merge identities + $this->daoMap[$daoClass][0] = ArrayUtils::mergeUnique( + $this->daoMap[$daoClass][0], + $daoMap[0] + ); + //merge workers uncachers + $this->daoMap[$daoClass][1]->merge($daoMap[1]); + } else { + $this->daoMap[$daoClass] = $daoMap; + } + } + + return $this; + } + } +?> \ No newline at end of file diff --git a/main/DAOs/Uncachers/UncacherNullDaoWorker.class.php b/main/DAOs/Uncachers/UncacherNullDaoWorker.class.php new file mode 100644 index 0000000000..344084bcd1 --- /dev/null +++ b/main/DAOs/Uncachers/UncacherNullDaoWorker.class.php @@ -0,0 +1,36 @@ + \ No newline at end of file diff --git a/main/DAOs/Uncachers/UncacherSmartDaoWorkerLists.class.php b/main/DAOs/Uncachers/UncacherSmartDaoWorkerLists.class.php new file mode 100644 index 0000000000..94e5ff6a10 --- /dev/null +++ b/main/DAOs/Uncachers/UncacherSmartDaoWorkerLists.class.php @@ -0,0 +1,92 @@ +classNameMap[$className] = array($indexKey, $intKey); + } + + public function getClassNameMap() + { + return $this->classNameMap; + } + + /** + * @param $uncacher UncacherSmartDaoWorkerLists same as self class + * @return BaseUncacher (this) + */ + public function merge(UncacherBase $uncacher) + { + Assert::isInstance($uncacher, get_class($this)); + return $this->mergeSelf($uncacher); + } + + public function uncache() + { + foreach ($this->classNameMap as $className => $classNameRow) { + list ($indexKey, $intKey) = $classNameRow; + $this->uncacheClassName($className, $indexKey, $intKey); + } + } + + protected function uncacheClassName($className, $indexKey, $intKey) { + $cache = Cache::me(); + $pool = SemaphorePool::me(); + + if ($pool->get($intKey)) { + $indexList = $cache->mark($className)->get($indexKey); + $cache->mark($className)->delete($indexKey); + + if ($indexList) { + foreach (array_keys($indexList) as $key) + $cache->mark($className)->delete($key); + } + + $pool->free($intKey); + + return true; + } + + $cache->mark($className)->delete($indexKey); + + return false; + } + + /** + * @param UncacherBaseDaoWorker $uncacher + * @return UncacherBaseDaoWorker + */ + private function mergeSelf(UncacherSmartDaoWorkerLists $uncacher) + { + foreach ($uncacher->getClassNameMap() as $className => $classNameRow) { + if (!isset($this->classNameMap[$className])) { + $this->classNameMap[$className] = $classNameRow; + } + } + return $this; + } + } +?> \ No newline at end of file diff --git a/main/DAOs/Uncachers/UncacherTaggableDaoWorker.class.php b/main/DAOs/Uncachers/UncacherTaggableDaoWorker.class.php new file mode 100644 index 0000000000..1f32c95d49 --- /dev/null +++ b/main/DAOs/Uncachers/UncacherTaggableDaoWorker.class.php @@ -0,0 +1,83 @@ +classNameMap[$className] = array(array($idKey), $tags, $worker); + } + + /** + * @return array + */ + public function getClassNameMap() + { + return $this->classNameMap; + } + /** + * @param $uncacher UncacherNullDaoWorker same as self class + * @return BaseUncacher (this) + */ + public function merge(UncacherBase $uncacher) + { + Assert::isInstance($uncacher, 'UncacherTaggableDaoWorker'); + return $this->mergeSelf($uncacher); + } + + public function uncache() + { + foreach ($this->classNameMap as $className => $uncaches) { + list($idKeys, $tags, $worker) = $uncaches; + /* @var $worker TaggableDaoWorker */ + $worker->expireTags($tags); + + foreach ($idKeys as $key) + Cache::me()->mark($className)->delete($idKey); + + ClassUtils::callStaticMethod("$className::dao")->uncacheLists(); + } + } + + private function mergeSelf(UncacherTaggableDaoWorker $uncacher) { + foreach ($uncacher->getClassNameMap() as $className => $uncaches) { + if (!isset($this->classNameMap[$className])) { + $this->classNameMap[$className] = $uncaches; + } else { + //merging idkeys + $this->classNameMap[$className][0] = ArrayUtils::mergeUnique( + $this->classNameMap[$className][0], + $uncaches[0] + ); + //merging tags + $this->classNameMap[$className][1] = ArrayUtils::mergeUnique( + $this->classNameMap[$className][1], + $uncaches[1] + ); + } + } + return $this; + } + } +?> \ No newline at end of file diff --git a/main/DAOs/Uncachers/UncacherVoodoDaoWorkerLists.class.php b/main/DAOs/Uncachers/UncacherVoodoDaoWorkerLists.class.php new file mode 100644 index 0000000000..be484951e6 --- /dev/null +++ b/main/DAOs/Uncachers/UncacherVoodoDaoWorkerLists.class.php @@ -0,0 +1,76 @@ +handlerList[$className] = $handler; + } + + public function getHandlerList() + { + return $this->handlerList; + } + + /** + * @param $uncacher UncacherVoodoDaoWorkerLists same as self class + * @return BaseUncacher (this) + */ + public function merge(UncacherBase $uncacher) + { + Assert::isInstance($uncacher, get_class($this)); + return $this->mergeSelf($uncacher); + } + + public function uncache() + { + foreach ($this->handlerList as $className => $handler) { + $this->uncacheClassName($className, $handler); + } + } + + protected function uncacheClassName($className, SegmentHandler $handler) { + $handler->drop(); + + $dao = ClassUtils::callStaticMethod($className.'::dao'); + /* @var $dao StorableDAO */ + return Cache::worker($dao)->uncacheByQuery($dao->makeSelectHead()); + } + + /** + * @param UncacherVoodoDaoWorkerLists $uncacher + * @return UncacherVoodoDaoWorkerLists + */ + private function mergeSelf(UncacherVoodoDaoWorkerLists $uncacher) + { + foreach ($uncacher->getHandlerList() as $className => $handler) { + if (!isset($this->handlerList[$className])) { + $this->handlerList[$className] = $handler; + } + } + return $this; + } + } +?> \ No newline at end of file diff --git a/main/DAOs/Uncachers/UncachersPool.class.php b/main/DAOs/Uncachers/UncachersPool.class.php new file mode 100644 index 0000000000..dd07620800 --- /dev/null +++ b/main/DAOs/Uncachers/UncachersPool.class.php @@ -0,0 +1,71 @@ +merge($uncacher); + } + + public function getUncachers() { + return $this->uncachers; + } + + /** + * @param $uncacher BaseUncacher same as self class + * @return BaseUncacher (this) + */ + public function merge(UncacherBase $uncacher) { + if ($uncacher instanceof UncachersPool) { + return $this->mergeSelf($uncacher); + } + return $this->mergeInstance($uncacher); + } + + public function uncache() { + foreach ($this->uncachers as $uncacher) { + /* @var $uncacher UncacherBase */ + $uncacher->uncache(); + } + } + + private function mergeInstance(UncacherBase $uncacher) { + $class = get_class($uncacher); + if (isset($this->uncachers[$class])) { + $this->uncachers[$class]->merge($uncacher); + } else { + $this->uncachers[$class] = $uncacher; + } + return $this; + } + + private function mergeSelf(UncachersPool $uncacher) { + foreach ($uncacher->getUncachers() as $subUncacher) { + $this->merge($subUncacher); + } + return $this; + } + } +?> \ No newline at end of file diff --git a/main/DAOs/Workers/BaseDaoWorker.class.php b/main/DAOs/Workers/BaseDaoWorker.class.php index fd67f3d22f..3f83da4a0d 100644 --- a/main/DAOs/Workers/BaseDaoWorker.class.php +++ b/main/DAOs/Workers/BaseDaoWorker.class.php @@ -84,16 +84,33 @@ public function dropByIds(array $ids) //@{ public function uncacheById($id) { - return - Cache::me()->mark($this->className)-> - delete($this->makeIdKey($id)); + return $this->registerUncacher($this->getUncacherById($id)); + } + + /** + * @return UncacherBase + */ + public function getUncacherById($id) + { + return UncacherBaseDaoWorker::create( + $this->className, + $this->makeIdKey($id) + ); } public function uncacheByQuery(SelectQuery $query) { - return - Cache::me()->mark($this->className)-> - delete($this->makeQueryKey($query, self::SUFFIX_QUERY)); + return $this->registerUncacher( + UncacherBaseDaoWorker::create( + $this->className, + $this->makeQueryKey($query, self::SUFFIX_QUERY) + ) + ); + } + + protected function registerUncacher(UncacherBase $uncacher) + { + return $this->dao->registerWorkerUncacher($uncacher); } //@} @@ -112,6 +129,7 @@ protected function getCachedByQuery(SelectQuery $query) Cache::me()->mark($this->className)-> get($this->makeQueryKey($query, self::SUFFIX_QUERY)); } + //@} /// fetchers @@ -178,4 +196,4 @@ protected function makeQueryKey(SelectQuery $query, $suffix) .$this->watermark; } } -?> \ No newline at end of file +?> diff --git a/main/DAOs/Workers/CacheDaoWorker.class.php b/main/DAOs/Workers/CacheDaoWorker.class.php index 8ddd626a84..6aec991bc8 100644 --- a/main/DAOs/Workers/CacheDaoWorker.class.php +++ b/main/DAOs/Workers/CacheDaoWorker.class.php @@ -65,14 +65,9 @@ protected function cacheListByQuery( //@{ public function uncacheLists() { - if ( - !Cache::me()-> - mark($this->className)-> - increment($this->className, 1) - ) - Cache::me()->mark($this->className)->delete($this->className); - - return true; + return $this->registerUncacher( + UncacherCacheDaoWorkerLists::create($this->className) + ); } //@} diff --git a/main/DAOs/Workers/CommonDaoWorker.class.php b/main/DAOs/Workers/CommonDaoWorker.class.php index 0da3497dbf..3e3069fdba 100644 --- a/main/DAOs/Workers/CommonDaoWorker.class.php +++ b/main/DAOs/Workers/CommonDaoWorker.class.php @@ -479,19 +479,29 @@ public function dropById($id) /// uncachers //@{ - public function uncacheById($id) + + /** + * @return UncacherBase + */ + public function getUncacherById($id) { - $this->dao->uncacheLists(); - - return parent::uncacheById($id); + return UncacherCommonDaoWorker::create( + $this->className, + $this->makeIdKey($id) + ); } public function uncacheByIds($ids) { + if (empty($ids)) + return; + + $uncacher = $this->getUncacherById(array_shift($ids)); + foreach ($ids as $id) - parent::uncacheById($id); + $uncacher->merge($this->getUncacherById($id)); - return $this->dao->uncacheLists(); + return $this->registerUncacher($uncacher->uncache()); } // quite useless here @@ -502,4 +512,4 @@ public function uncacheLists() } //@} } -?> \ No newline at end of file +?> diff --git a/main/DAOs/Workers/DalayedDropDaoWorker.class.php b/main/DAOs/Workers/DalayedDropDaoWorker.class.php index a0ff5a65ce..6f1296437d 100644 --- a/main/DAOs/Workers/DalayedDropDaoWorker.class.php +++ b/main/DAOs/Workers/DalayedDropDaoWorker.class.php @@ -30,6 +30,14 @@ public function uncacheById($id) return true; } + /** + * @param mixed $id + * @return UncacherBase + */ + public function getUncacherById($id) { + return UncacherNullDaoWorker::create(); + } + public function dropWith($worker) { Assert::classExists($worker); @@ -46,4 +54,4 @@ public function dropWith($worker) } //@} } -?> \ No newline at end of file +?> diff --git a/main/DAOs/Workers/NullDaoWorker.class.php b/main/DAOs/Workers/NullDaoWorker.class.php index 1e165e263d..0bca425ec4 100644 --- a/main/DAOs/Workers/NullDaoWorker.class.php +++ b/main/DAOs/Workers/NullDaoWorker.class.php @@ -126,6 +126,13 @@ public function uncacheById($id) return true; } + /** + * @return UncacherNullDaoWorker + */ + public function getUncacherById($id) { + return UncacherNullDaoWorker::create(); + } + public function uncacheByIds($ids) { return true; @@ -155,4 +162,4 @@ protected function getCachedByQuery(SelectQuery $query) } //@} } -?> \ No newline at end of file +?> diff --git a/main/DAOs/Workers/SmartDaoWorker.class.php b/main/DAOs/Workers/SmartDaoWorker.class.php index 0b294d9639..5782c9d0e3 100644 --- a/main/DAOs/Workers/SmartDaoWorker.class.php +++ b/main/DAOs/Workers/SmartDaoWorker.class.php @@ -100,27 +100,9 @@ protected function cacheListByQuery( public function uncacheLists() { $intKey = $this->keyToInt($this->indexKey); - - $cache = Cache::me(); - $pool = SemaphorePool::me(); - - if ($pool->get($intKey)) { - $indexList = $cache->mark($this->className)->get($this->indexKey); - $cache->mark($this->className)->delete($this->indexKey); - - if ($indexList) { - foreach (array_keys($indexList) as $key) - $cache->mark($this->className)->delete($key); - } - - $pool->free($intKey); - - return true; - } - - $cache->mark($this->className)->delete($this->indexKey); - - return false; + return $this->registerUncacher( + UncacherSmartDaoWorkerLists::create($this->className, $this->indexKey, $intKey) + ); } //@} diff --git a/main/DAOs/Workers/VoodooDaoWorker.class.php b/main/DAOs/Workers/VoodooDaoWorker.class.php index 3fdec100a0..9d700f63b3 100644 --- a/main/DAOs/Workers/VoodooDaoWorker.class.php +++ b/main/DAOs/Workers/VoodooDaoWorker.class.php @@ -29,6 +29,9 @@ final class VoodooDaoWorker extends TransparentDaoWorker { private $classKey = null; + /** + * @var SegmentHandler + */ private $handler = null; // will trigger auto-detect @@ -99,9 +102,9 @@ protected function cacheListByQuery( //@{ public function uncacheLists() { - $this->handler->drop(); - - return parent::uncacheLists(); + return $this->registerUncacher( + UncacherVoodoDaoWorkerLists::create($this->className, $this->handler) + ); } //@} From dfcde55b4bd8b3178af303580936b2bbb798dee9 Mon Sep 17 00:00:00 2001 From: AlexeyDsov Date: Tue, 3 Jul 2012 13:21:51 +0400 Subject: [PATCH 2/2] added Introducing Uncachers to doc/ChangeLog --- doc/ChangeLog | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/doc/ChangeLog b/doc/ChangeLog index 31a0324a8c..0ccc248e4a 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,30 @@ +2012-07-03 Alexey S. Denisov + + * core/Cache/Cache.class.php + core/DB/DB.class.php + global.inc.php.tpl + main/DAOs/BaseDAO.class.php + main/DAOs/GenericDAO.class.php + main/DAOs/Uncachers/UncacherBase.class.php + main/DAOs/Uncachers/UncacherBaseDaoWorker.class.php + main/DAOs/Uncachers/UncacherCacheDaoWorkerLists.class.php + main/DAOs/Uncachers/UncacherCommonDaoWorker.class.php + main/DAOs/Uncachers/UncacherGenericDAO.class.php + main/DAOs/Uncachers/UncacherNullDaoWorker.class.php + main/DAOs/Uncachers/UncacherSmartDaoWorkerLists.class.php + main/DAOs/Uncachers/UncacherTaggableDaoWorker.class.php + main/DAOs/Uncachers/UncacherVoodoDaoWorkerLists.class.php + main/DAOs/Uncachers/UncachersPool.class.php + main/DAOs/Workers/BaseDaoWorker.class.php + main/DAOs/Workers/CacheDaoWorker.class.php + main/DAOs/Workers/CommonDaoWorker.class.php + main/DAOs/Workers/DalayedDropDaoWorker.class.php + main/DAOs/Workers/NullDaoWorker.class.php + main/DAOs/Workers/SmartDaoWorker.class.php + main/DAOs/Workers/VoodooDaoWorker.class.php: + + Introducing Uncachers + 2012-06-29 N. Konstantinov * core/DB/PgSQL.class.php