Index: core/kernel/managers/cache_manager.php =================================================================== --- core/kernel/managers/cache_manager.php +++ core/kernel/managers/cache_manager.php @@ -800,12 +800,29 @@ $this->setCache($serial_name, (int)$this->getCache($serial_name) + 1); if (!defined('IS_INSTALL') || !IS_INSTALL) { - // delete cached mod-rewrite urls related to given prefix and id - $delete_clause = isset($id) ? $prefix . ':' . $id : $prefix; + if ( $this->Application->isCachingType(CACHING_TYPE_MEMORY) ) { + $prefixes = $this->Application->getCache('cached_urls_unit_prefixes'); + } + else { + $prefixes = $this->Application->getDBCache('cached_urls_unit_prefixes'); - $sql = 'DELETE FROM ' . TABLE_PREFIX . 'CachedUrls - WHERE Prefixes LIKE ' . $this->Conn->qstr('%|' . $delete_clause . '|%'); - $this->Conn->Query($sql); + if ( $prefixes !== false ) { + $prefixes = unserialize($prefixes); + } + } + + if ( !$prefixes ) { + $prefixes = array('c', 'lang', 'theme'); + } + + if ( in_array($prefix, $prefixes) ) { + // delete cached mod-rewrite urls related to given prefix and id + $delete_clause = isset($id) ? $prefix . ':' . $id : $prefix; + + $sql = 'DELETE FROM ' . TABLE_PREFIX . 'CachedUrls + WHERE Prefixes LIKE ' . $this->Conn->qstr('%|' . $delete_clause . '|%'); + $this->Conn->Query($sql); + } } } Index: core/units/admin/admin_config.php =================================================================== --- core/units/admin/admin_config.php +++ core/units/admin/admin_config.php @@ -30,6 +30,7 @@ 'ScheduledTasks' => Array ( 'optimize_performance' => Array ('EventName' => 'OnOptimizePerformance', 'RunSchedule' => '0 0 * * *'), + 'populate_url_unit_cache' => array('EventName' => 'OnPopulateUrlUnitCacheScheduledTask', 'RunSchedule' => '0 * * * *'), ), 'TitlePresets' => Array ( Index: core/units/admin/admin_events_handler.php =================================================================== --- core/units/admin/admin_events_handler.php +++ core/units/admin/admin_events_handler.php @@ -1219,6 +1219,38 @@ } } } + + /** + * Populates URL unit cache + * + * @param kEvent $event Event. + * + * @return void + */ + protected function OnPopulateUrlUnitCacheScheduledTask(kEvent $event) + { + $sql = 'SELECT DISTINCT Prefixes + FROM ' . TABLE_PREFIX . 'CachedUrls'; + $urls = $this->Conn->GetColIterator($sql); + $prefixes = array(); + + foreach ( $urls as $url_prefixes ) { + $url_prefixes = explode('|', trim($url_prefixes, '|')); + + foreach ( $url_prefixes as $url_prefix ) { + $url_prefix = explode(':', $url_prefix); + $prefixes[$url_prefix[0]] = 1; + } + } + + if ( $this->Application->isCachingType(CACHING_TYPE_MEMORY) ) { + $this->Application->setCache('cached_urls_unit_prefixes', array_keys($prefixes), 3600); + } + else { + $this->Application->setDBCache('cached_urls_unit_prefixes', serialize(array_keys($prefixes)), 3600); + } + } + }