public static function getZendCache() { if (!isset(self::$_zendCache)) { self::$_zendCache = new Kwf_Component_Cache_MemoryZend(); } return self::$_zendCache; }
public function update() { //clear all view caches, required for 7a36ae58a Kwf_Component_Cache_Memory::getInstance()->_clean(); Kwf_Registry::get('db')->query('TRUNCATE cache_component'); Kwf_Registry::get('db')->query('TRUNCATE cache_component_includes'); }
public function update() { $db = Kwf_Registry::get('db'); $db->query("TRUNCATE `cache_component`;"); $db->query("ALTER TABLE `cache_component` ADD `tag` VARCHAR( 255 ) CHARACTER SET ASCII COLLATE ascii_bin NOT NULL AFTER `value`;"); $db->query("ALTER TABLE `cache_component` ADD INDEX `tag` ( `tag` );"); //because of TRUNCATE above we need to clear the whole memory cache Kwf_Component_Cache_Memory::getInstance()->_clean(); }
public function indexAction() { Zend_Registry::set('db', false); Kwf_Test_SeparateDb::setDbFromCookie(); // setzt es nur wenn es das cookie wirklich gibt //FnF models setzen damit tests nicht in echte tabellen schreiben Kwf_Component_Cache::setInstance(Kwf_Component_Cache::CACHE_BACKEND_FNF); Kwf_Component_Cache_Memory::setInstance(new Kwf_Component_Cache_MemoryBlackHole()); /* if (class_exists('APCIterator')) { $prefix = Kwf_Cache::getUniquePrefix(); apc_delete_file(new APCIterator('user', '#^'.$prefix.'#')); } else { apc_clear_cache('user'); } */ Kwf_Component_Data_Root::setComponentClass($this->_getParam('root')); Zend_Registry::set('testRootComponentClass', $this->_getParam('root')); $root = Kwf_Component_Data_Root::getInstance(); $root->setFilename('kwf/kwctest/' . $this->_getParam('root')); $url = $this->_getParam('url'); $urlParts = explode('/', $url); if (is_array($urlParts) && $urlParts[0] == 'media') { if (sizeof($urlParts) != 7) { throw new Kwf_Exception_NotFound(); } $class = $urlParts[1]; $id = $urlParts[2]; $type = $urlParts[3]; $checksum = $urlParts[4]; // time() wäre der 5er, wird aber nur wegen browsercache benötigt $filename = $urlParts[6]; if ($checksum != Kwf_Media::getChecksum($class, $id, $type, $filename)) { throw new Kwf_Exception_AccessDenied('Access to file not allowed.'); } Kwf_Media_Output::output(Kwf_Media::getOutput($class, $id, $type)); } if ($url == 'kwf/util/kwc/render') { if (isset($_REQUEST['url'])) { $_REQUEST['url'] = str_replace('/' . $root->filename, '', $_REQUEST['url']); } Kwf_Util_Component::dispatchRender(); } $domain = 'http://' . Zend_Registry::get('config')->server->domain; $data = $root->getPageByUrl($domain . Kwf_Setup::getBaseUrl() . '/' . $url, null); if (!$data) { throw new Kwf_Exception_NotFound(); } $root->setCurrentPage($data); $contentSender = Kwc_Abstract::getSetting($data->componentClass, 'contentSender'); $contentSender = new $contentSender($data); $contentSender->sendContent(true); Kwf_Benchmark::shutDown(); Kwf_Benchmark::output(); exit; }
protected function _init($componentClass) { Kwf_Component_Data_Root::setComponentClass($componentClass); Zend_Session::$_unitTestEnabled = true; $this->_root = Kwf_Component_Data_Root::getInstance(); $this->_root->setFilename('kwf/kwctest/' . $componentClass); if (function_exists('apc_clear_cache')) { apc_clear_cache('user'); } Kwf_Component_Cache_Memory::getInstance()->_clean(); Kwf_Cache_Simple::resetZendCache(); Kwc_FulltextSearch_MetaModel::setInstance(new Kwf_Model_FnF(array('primaryKey' => 'page_id'))); Kwf_Assets_Package_Default::clearInstances(); Kwf_Component_LogDuplicateModel::setInstance(new Kwf_Model_FnF(array())); Kwf_Media_MemoryCache::getInstance()->clean(); return $this->_root; }
public function deleteViewCache($select, $progressBarAdapter = null) { $microtime = $this->_getMicrotime(); $select->whereEquals('deleted', false); $model = $this->getModel(); $log = Kwf_Events_Log::getInstance(); $cacheIds = array(); $options = array('columns' => array('component_id', 'renderer', 'type', 'value')); $partialIds = array(); $deleteIds = array(); $checkIncludeIds = array(); $rows = $model->export(Kwf_Model_Abstract::FORMAT_ARRAY, $select, $options); $progress = null; if ($progressBarAdapter) { $count = count($rows); $steps = (int) (count($rows) * 2 / 100 + 3); $step = 0; $progress = new Zend_ProgressBar($progressBarAdapter, 0, $steps); } foreach ($rows as $key => $row) { if ($progress && $key % 100 == 0) { $step += 100; $progress->next(1, "viewcache {$step} / {$count}"); } $cacheIds[] = $this->_getCacheId($row['component_id'], $row['renderer'], $row['type'], $row['value']); Kwf_Benchmark::countLog('viewcache-delete-' . $row['type']); if ($row['type'] != 'fullPage' && !isset($checkIncludeIds[$row['component_id']])) { $checkIncludeIds[$row['component_id']] = true; } if ($log) { $log->log("delete view cache {$row['component_id']} {$row['renderer']} {$row['type']} {$row['value']}", Zend_Log::INFO); } $type = $row['type']; $value = $row['value']; $cId = $row['component_id']; if ($type == 'partial' && $value != '') { if (!isset($partialIds[$cId])) { $partialIds[$cId] = array(); } $partialIds[$cId][] = $value; } else { if ($value == '') { if (!isset($deleteIds[$type])) { $deleteIds[$type] = array(); } $deleteIds[$type][] = $cId; } else { throw new Kwf_Exception('Should not happen.'); } } } // Memcache $this->_beforeMemcacheDelete($select); // For unit testing - DO NOT DELETE! if ($progress) { $step = 0; } foreach ($cacheIds as $key => $cacheId) { if ($progress && $key % 100 == 0) { $step += 100; $progress->next(1, "memcache {$step} / {$count}"); } Kwf_Component_Cache_Memory::getInstance()->remove($cacheId, $microtime); } $this->_afterMemcacheDelete($select); // For unit testing - DO NOT DELETE! // FullPage if ($progress) { $progress->next(1, "fullPage"); } $s = new Kwf_Model_Select(); $s->whereEquals('type', 'fullPage'); if ($checkIncludeIds) { $ids = array_keys($this->_fetchIncludesTree(array_keys($checkIncludeIds))); if ($ids) { foreach ($ids as &$id) { $id = (string) $id; } unset($id); $s->whereEquals('component_id', $ids); if ($log) { foreach ($ids as $id) { $log->log("type=fullPage component_id={$id}", Zend_Log::INFO); } } $this->deleteViewCache($s); } } // Database $this->_beforeDatabaseDelete($select); // For unit testing - DO NOT DELETE! if ($progress) { $progress->next(1, "partialIds"); } foreach ($partialIds as $componentId => $values) { $select = $model->select(); $select->where(new Kwf_Model_Select_Expr_And(array(new Kwf_Model_Select_Expr_Equals('component_id', (string) $componentId), new Kwf_Model_Select_Expr_Equals('type', 'partial'), new Kwf_Model_Select_Expr_Equals('value', $values), new Kwf_Model_Select_Expr_LowerEqual('microtime', $microtime)))); $model->updateRows(array('deleted' => true), $select); } if ($progress) { $progress->next(1, "deleteIds"); } foreach ($deleteIds as $type => $componentIds) { $select = $model->select(); $select->where(new Kwf_Model_Select_Expr_And(array(new Kwf_Model_Select_Expr_Equals('component_id', $componentIds), new Kwf_Model_Select_Expr_Equals('type', $type), new Kwf_Model_Select_Expr_LowerEqual('microtime', $microtime)))); $model->updateRows(array('deleted' => true), $select); } $this->_afterDatabaseDelete($select); // For unit testing - DO NOT DELETE! if ($progress) { $progress->finish(); } file_put_contents('log/clear-view-cache', date('Y-m-d H:i:s') . ' ' . round(microtime(true) - Kwf_Benchmark::$startTime, 2) . 's; ' . Kwf_Events_Dispatcher::$eventsCount . ' events; ' . count($deleteIds) . ' view cache entries deleted; ' . (isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '') . "\n", FILE_APPEND); return count($cacheIds); }