Example #1
0
 /**
  * Returns if the given component requests https
  *
  * Return value is cached.
  */
 public static function doesComponentRequestHttps(Kwf_Component_Data $data)
 {
     $showInvisible = Kwf_Component_Data_Root::getShowInvisible();
     $foundRequestHttps = false;
     if (!$showInvisible) {
         //don't cache in preview
         $cacheId = 'reqHttps-' . $data->componentId;
         $foundRequestHttps = Kwf_Cache_Simple::fetch($cacheId);
     }
     if ($foundRequestHttps === false) {
         $foundRequestHttps = 0;
         //don't use false, false means not-cached
         if (Kwf_Component_Abstract::getFlag($data->componentClass, 'requestHttps')) {
             $foundRequestHttps = true;
         }
         if (!$foundRequestHttps && $data->getRecursiveChildComponents(array('page' => false, 'flags' => array('requestHttps' => true)))) {
             $foundRequestHttps = true;
         }
         if (!$showInvisible) {
             //don't cache in preview
             Kwf_Cache_Simple::add($cacheId, $foundRequestHttps);
         }
     }
     return $foundRequestHttps;
 }
Example #2
0
 public function testPluginWithMaster()
 {
     $c = $this->_root->getComponentByClass('Kwf_Component_Plugin_Interface_UseViewCache_Component');
     Kwf_Component_Plugin_Interface_UseViewCache_Plugin_Component::$useViewCache = true;
     $html1 = $c->render(true, true);
     Kwf_Component_Plugin_Interface_UseViewCache_Component::$num++;
     $html2 = $c->render(true, true);
     Kwf_Component_Plugin_Interface_UseViewCache_Component::$num++;
     $html3 = $c->render(true, true);
     Kwf_Component_Plugin_Interface_UseViewCache_Component::$num++;
     $this->assertEquals($html1, $html2);
     $this->assertEquals($html1, $html3);
     apc_clear_cache('user');
     Kwf_Cache::factory('Core', 'Memcached', array('lifetime' => null, 'automatic_cleaning_factor' => false, 'automatic_serialization' => true))->clean();
     Kwf_Cache_Simple::resetZendCache();
     Kwf_Component_Plugin_Interface_UseViewCache_Plugin_Component::$useViewCache = false;
     $html4 = $c->render(true, true);
     Kwf_Component_Plugin_Interface_UseViewCache_Component::$num++;
     $html5 = $c->render(true, true);
     Kwf_Component_Plugin_Interface_UseViewCache_Component::$num++;
     $html6 = $c->render(true, true);
     Kwf_Component_Plugin_Interface_UseViewCache_Component::$num++;
     $this->assertNotEquals($html3, $html4);
     $this->assertNotEquals($html4, $html5);
     $this->assertNotEquals($html4, $html6);
     $this->assertNotEquals($html5, $html6);
     Kwf_Component_Plugin_Interface_UseViewCache_Plugin_Component::$useViewCache = true;
     $html7 = $c->render(true, true);
     Kwf_Component_Plugin_Interface_UseViewCache_Component::$num++;
     $html8 = $c->render(true, true);
     Kwf_Component_Plugin_Interface_UseViewCache_Component::$num++;
     $this->assertEquals($html7, $html3);
     $this->assertEquals($html8, $html3);
 }
 /**
  * returns a list of all visible favourite componentIds
  */
 public static function getFavouriteComponentIds($favouritesModel)
 {
     $ret = array();
     $userId = Kwf_Registry::get('userModel')->getAuthedUserId();
     if ($userId) {
         $cacheIdUser = '******' . $userId;
         $ret = Kwf_Cache_Simple::fetch($cacheIdUser, $success);
         if (!$success) {
             // get all favourites related to user
             $select = new Kwf_Model_Select();
             $select->whereEquals('user_id', $userId);
             $favouritesModel = Kwf_Model_Abstract::getInstance($favouritesModel);
             $favourites = $favouritesModel->getRows($select);
             $componentIds = array();
             foreach ($favourites as $favourite) {
                 $component = Kwf_Component_Data_Root::getInstance()->getComponentById($favourite->component_id);
                 // check if component is visible and existent
                 if ($component) {
                     // if component is visible create list of users related to component
                     $componentIds[] = $component->componentId;
                 }
             }
             // cache relation of visible components to user
             Kwf_Cache_Simple::add($cacheIdUser, $componentIds);
             $ret = $componentIds;
         }
     }
     return $ret;
 }
 public function update()
 {
     //clear all view caches, required for 7a36ae58a
     Kwf_Cache_Simple::getMemcache()->flush();
     Kwf_Registry::get('db')->query('TRUNCATE cache_component');
     Kwf_Registry::get('db')->query('TRUNCATE cache_component_includes');
 }
Example #5
0
 /**
  * @internal über row aufrufen!
  */
 public function getRecursiveIds($parentId)
 {
     $ret = false;
     if ($this->useRecursiveIdsCache()) {
         $cacheId = 'recid-' . $this->getUniqueIdentifier() . '-' . (string) $parentId;
         $ret = Kwf_Cache_Simple::fetch($cacheId);
     }
     if ($ret === false) {
         if (!isset($this->_parentIdsCache)) {
             foreach ($this->export(Kwf_Model_Interface::FORMAT_ARRAY, array()) as $row) {
                 $this->_parentIdsCache[$row[$this->getPrimaryKey()]] = $row[$this->_referenceMap['Parent']['column']];
             }
         }
         $ret = array($parentId);
         foreach (array_keys($this->_parentIdsCache, $parentId) as $v) {
             $ret[] = $v;
             $ret = array_merge($ret, $this->getRecursiveIds($v));
         }
         $ret = array_values(array_unique($ret));
         if ($this->useRecursiveIdsCache()) {
             Kwf_Cache_Simple::add($cacheId, $ret);
         }
     }
     return $ret;
 }
 public function testApcCli()
 {
     Kwf_Cache_Simple::add('foo', 'bar', 1);
     $this->assertEquals(Kwf_Cache_Simple::fetch('foo'), 'bar');
     sleep(2);
     $this->assertFalse(Kwf_Cache_Simple::fetch('foo'));
 }
Example #7
0
 public function jsonIndexAction()
 {
     if ($this->_getParam('subrootComponentId')) {
         $cacheId = 'kwcMenuMobile-root-' . $this->_getParam('subrootComponentId') . '-' . $this->_getParam('class');
     } else {
         if ($this->_getParam('pageId')) {
             $cacheId = 'kwcMenuMobile-' . $this->_getParam('pageId');
         }
     }
     $data = Kwf_Cache_Simple::fetch($cacheId);
     if ($data === false) {
         if ($this->_getParam('subrootComponentId')) {
             $pages = $this->_getChildPages();
         } else {
             if ($this->_getParam('pageId')) {
                 $component = Kwf_Component_Data_Root::getInstance()->getComponentById($this->_getParam('pageId'));
                 $pages = $this->_getChildPagesRecursive(array($component), 2);
                 foreach ($pages as $k => $p) {
                     unset($pages[$k]['name']);
                     unset($pages[$k]['url']);
                 }
             }
         }
         $data = array('lifetime' => 60 * 60, 'mimeType' => 'application/json', 'mtime' => time(), 'contents' => json_encode(array('pages' => $pages)));
         Kwf_Cache_Simple::add($cacheId, $data);
     }
     Kwf_Media_Output::output($data);
 }
Example #8
0
 public function setUp()
 {
     if (Kwf_Cache_Simple::getBackend() == 'apc') {
         $this->markTestSkipped("Test doesn't work with apc in cli.");
     }
     parent::setUp('Kwf_Component_Cache_Mysql_Root_Component');
     Kwf_Component_Cache::setInstance(new Kwf_Component_Cache_Mysql_Cache());
 }
 public function update()
 {
     if (Kwf_Cache_Simple::getMemcache()) {
         Kwf_Cache_Simple::getMemcache()->flush();
     }
     Kwf_Registry::get('db')->query('TRUNCATE cache_component');
     Kwf_Registry::get('db')->query('ALTER TABLE `cache_component` ADD `microtime` BIGINT( 14 ) NOT NULL AFTER `value`');
 }
 public function onComponentAdded(Kwf_Component_Event_Component_Added $ev)
 {
     $page = $ev->component->getPage();
     if ($page) {
         $cacheId = 'reqHttps-' . $page->componentId;
         Kwf_Cache_Simple::delete($cacheId);
     }
 }
 protected function _clearCache($options)
 {
     if (Kwf_Config::getValue('cacheSimpleNamespace')) {
         $this->_output("change cacheSimpleNamespace config setting to clear");
     } else {
         Kwf_Cache_Simple::_clear();
     }
 }
Example #12
0
 public function setUp()
 {
     apc_clear_cache('user');
     Kwf_Cache::factory('Core', 'Memcached', array('lifetime' => null, 'automatic_cleaning_factor' => false, 'automatic_serialization' => true))->clean();
     Kwf_Cache_Simple::resetZendCache();
     parent::setUp();
     Kwf_Events_Dispatcher::addListeners('Kwf_Model_RowCache_RowCacheModel');
     Kwf_Model_Abstract::getInstance('Kwf_Model_RowCache_SourceModel')->setData(array(array('id' => 1, 'foo' => 1, 'bar' => 'x1'), array('id' => 2, 'foo' => 2, 'bar' => 'x2'), array('id' => 3, 'foo' => 3, 'bar' => 'x3'), array('id' => 4, 'foo' => 4, 'bar' => 'x4')));
 }
 public function onComponentAddedOrRemoved(Kwf_Component_Event_Component_Abstract $event)
 {
     $cacheId = 'procI-' . $event->component->getPageOrRoot()->componentId;
     Kwf_Cache_Simple::delete($cacheId);
     $log = Kwf_Events_Log::getInstance();
     if ($log) {
         $log->log("processInput cache clear componentId=" . $event->component->getPageOrRoot()->componentId, Zend_Log::INFO);
     }
 }
Example #14
0
 private function _deleteCache($dbId)
 {
     foreach (Kwf_Component_Data_Root::getInstance()->getComponentsByDbId($dbId) as $c) {
         foreach (array('intern', 'external') as $i) {
             $cacheId = 'articleCategoryCount' . $c->componentId . $i;
             Kwf_Cache_Simple::delete($cacheId);
         }
     }
 }
 public static function __getProcessInputComponents($data)
 {
     $showInvisible = Kwf_Component_Data_Root::getShowInvisible();
     $cacheId = 'procI-' . $data->componentId;
     $success = false;
     if (!$showInvisible) {
         //don't cache in preview
         $cacheContents = Kwf_Cache_Simple::fetch($cacheId, $success);
         //cache is cleared in Kwf_Component_Events_ProcessInputCache
     }
     if (!$success) {
         $datas = array();
         foreach (self::_findProcessInputComponents($data) as $p) {
             $plugins = array();
             $c = $p;
             do {
                 foreach ($c->getPlugins('Kwf_Component_Plugin_Interface_SkipProcessInput') as $i) {
                     $plugins[] = array('pluginClass' => $i, 'componentId' => $c->componentId);
                 }
                 $isPage = $c->isPage;
                 $c = $c->parent;
             } while ($c && !$isPage);
             $datas[] = array('data' => $p, 'plugins' => $plugins);
         }
         if (!$showInvisible) {
             $cacheContents = array();
             foreach ($datas as $p) {
                 $cacheContents[] = array('data' => $p['data']->kwfSerialize(), 'plugins' => $p['plugins']);
             }
             Kwf_Cache_Simple::add($cacheId, $cacheContents);
         }
     } else {
         $datas = array();
         foreach ($cacheContents as $d) {
             $datas[] = array('data' => Kwf_Component_Data::kwfUnserialize($d['data']), 'plugins' => $d['plugins']);
         }
     }
     //ask SkipProcessInput plugins if it should be skipped
     //evaluated every time
     $process = array();
     foreach ($datas as $d) {
         foreach ($d['plugins'] as $p) {
             $plugin = Kwf_Component_Plugin_Abstract::getInstance($p['pluginClass'], $p['componentId']);
             $result = $plugin->skipProcessInput();
             if ($result === Kwf_Component_Plugin_Interface_SkipProcessInput::SKIP_SELF_AND_CHILDREN) {
                 continue 2;
             }
             if ($result === Kwf_Component_Plugin_Interface_SkipProcessInput::SKIP_SELF && $p['componentId'] == $d['data']->componentId) {
                 continue 2;
             }
         }
         $process[] = $d['data'];
     }
     return $process;
 }
 protected function _clearCache($options)
 {
     $skipOtherServers = isset($options['skipOtherServers']) ? $options['skipOtherServers'] : false;
     if (!$skipOtherServers) {
         //namespace used in Kwf_Cache_Simple
         $mc = Kwf_Cache_Simple::getMemcache();
         if ($mc->get(Kwf_Cache_Simple::getUniquePrefix() . 'cache_namespace')) {
             $mc->increment(Kwf_Cache_Simple::getUniquePrefix() . 'cache_namespace');
         }
     }
 }
 private function _setup($rootClass)
 {
     Kwf_Component_Data_Root::setComponentClass($rootClass);
     $this->_root = Kwf_Component_Data_Root::getInstance();
     $this->_renderer = new Kwf_Component_Renderer();
     $this->_renderer->setEnableCache(true);
     Kwf_Component_Cache::setInstance(Kwf_Component_Cache::CACHE_BACKEND_FNF);
     apc_clear_cache('user');
     Kwf_Cache::factory('Core', 'Memcached', array('lifetime' => null, 'automatic_cleaning_factor' => false, 'automatic_serialization' => true))->clean();
     Kwf_Cache_Simple::resetZendCache();
 }
Example #18
0
 public function getValue($name)
 {
     if (PHP_SAPI == 'cli') {
         return (int) Kwf_Util_Apc::callUtil('get-counter-value', array('name' => $name), array('returnBody' => true));
     } else {
         static $prefix;
         if (!isset($prefix)) {
             $prefix = Kwf_Cache_Simple::getUniquePrefix() . 'bench-';
         }
         return (int) apc_fetch($prefix . $name);
     }
 }
 public function onRowUpdatesFinished(Kwf_Events_Event_Row_UpdatesFinished $event)
 {
     if (count($this->_orExpr->getExpressions())) {
         $select = new Kwf_Model_Select();
         $select->where($this->_orExpr);
         $rows = Kwf_Component_Cache::getInstance()->getModel('url')->export(Kwf_Model_Abstract::FORMAT_ARRAY, $select);
         foreach ($rows as $row) {
             $cacheId = 'url-' . $row['url'];
             Kwf_Cache_Simple::delete($cacheId);
         }
     }
 }
 public function setUp()
 {
     parent::setUp();
     //clear view cache
     Kwf_Cache::factory('Core', 'Memcached', array('lifetime' => null, 'automatic_cleaning_factor' => false, 'automatic_serialization' => true))->clean();
     Kwf_Cache_Simple::resetZendCache();
     Kwf_Component_Data_Root::setComponentClass('Kwc_FavouritesSelenium_Root');
     //use custom user model
     $this->presetModel = Kwf_Registry::get('config')->user->model;
     Kwf_Registry::get('config')->user->model = 'Kwc_FavouritesSelenium_UserModel';
     //unset existing userModel instance to get new one
     $reg = Kwf_Registry::getInstance()->set('userModel', Kwf_Model_Abstract::getInstance('Kwc_FavouritesSelenium_UserModel'));
 }
 public function jsonIndexAction()
 {
     if ($this->_getParam('subrootComponentId')) {
         $cacheId = 'kwcMenuMobile-root-' . $this->_getParam('subrootComponentId') . '-' . $this->_getParam('class');
     } else {
         if ($this->_getParam('pageId')) {
             $cacheId = 'kwcMenuMobile-' . $this->_getParam('pageId');
         }
     }
     foreach (Kwf_Component_Data_Root::getInstance()->getPlugins('Kwf_Component_PluginRoot_Interface_PreDispatch') as $plugin) {
         $plugin->preDispatch($this->_getParam('pageUrl'));
     }
     $data = Kwf_Cache_Simple::fetch($cacheId);
     if ($data === false) {
         if ($this->_getParam('subrootComponentId')) {
             $pages = $this->_getChildPages();
         } else {
             if ($this->_getParam('pageId')) {
                 $component = Kwf_Component_Data_Root::getInstance()->getComponentById($this->_getParam('pageId'));
                 $pages = $this->_getChildPagesRecursive(array($component), 2);
                 foreach ($pages as $k => $p) {
                     unset($pages[$k]['name']);
                     unset($pages[$k]['url']);
                 }
             }
         }
         $data = array('lifetime' => 60 * 60, 'mimeType' => 'application/json', 'mtime' => time(), 'contents' => json_encode(array('pages' => $pages)));
         Kwf_Cache_Simple::add($cacheId, $data);
     }
     $skipProcessPages = true;
     foreach (Kwf_Component_Data_Root::getInstance()->getPlugins('Kwf_Component_PluginRoot_Interface_MaskComponent') as $plugin) {
         if (!$plugin->canIgnoreMasks()) {
             $skipProcessPages = false;
         }
     }
     foreach (Kwf_Component_Data_Root::getInstance()->getPlugins('Kwf_Component_PluginRoot_Interface_PostRender') as $plugin) {
         if (!$plugin->canIgnoreProcessUrl()) {
             $skipProcessPages = false;
         }
     }
     if (!$skipProcessPages) {
         $contents = json_decode($data['contents'], true);
         $contents['pages'] = $this->_processPages($contents['pages']);
         $data['contents'] = json_encode($contents);
     }
     Kwf_Media_Output::output($data);
 }
Example #22
0
 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;
 }
Example #23
0
 private function _deleteCache($event)
 {
     $page = $event->component->getParentPageOrRoot()->getParentPageOrRoot();
     $d = $page;
     while ($d) {
         if (Kwc_Abstract::getFlag($d->componentClass, 'subroot') || $d->componentId == 'root') {
             Kwf_Cache_Simple::delete('kwcMenuMobile-root-' . $d->componentId);
             break;
         } else {
             if ($d->isPage) {
                 Kwf_Cache_Simple::delete('kwcMenuMobile-' . $d->componentId);
                 break;
             }
         }
         $d = $d->parent;
     }
 }
 public function useViewCache($renderer)
 {
     $cacheId = 'paging-' . $this->_componentId;
     $disableCacheParam = Kwf_Cache_Simple::fetch($cacheId, $success);
     if (!$success) {
         $disableCacheParam = null;
         $c = Kwf_Component_Data_Root::getInstance()->getComponentById($this->_componentId, array('ignoreVisible' => true))->parent->getComponent();
         if ($c instanceof Kwc_Directories_List_View_Component && $c->hasSearchForm()) {
             $disableCacheParam = $c->getSearchForm()->componentId . '-post';
         }
         Kwf_Cache_Simple::add($cacheId, $disableCacheParam);
     }
     $ret = true;
     if ($disableCacheParam) {
         $ret = !isset($_REQUEST[$disableCacheParam]);
     }
     return $ret;
 }
 public function memcacheAction()
 {
     if (!Kwf_Cache_Simple::$memcacheHost) {
         echo "memcache not configured for host\n";
         exit;
     }
     $s = Kwf_Cache_Simple::$memcacheHost . ':' . Kwf_Cache_Simple::$memcachePort;
     echo "Clear the complete memcache on {$s}?\nThis will effect all other webs using this memcache host.\nAre you REALLY sure you want to do that? [N/y]\n";
     $stdin = fopen('php://stdin', 'r');
     $input = trim(strtolower(fgets($stdin, 2)));
     fclose($stdin);
     if ($input == 'y') {
         Kwf_Cache_Simple::getMemcache()->flush();
         echo "done\n";
         exit;
     }
     exit(1);
 }
 public function __construct()
 {
     $options = array('lifetime' => null, 'write_control' => false, 'automatic_cleaning_factor' => 0, 'automatic_serialization' => true);
     parent::__construct($options);
     $be = Kwf_Cache_Simple::getBackend();
     if ($be == 'memcache' || $be == 'redis') {
         throw new Kwf_Exception("don't use thru Zend_Cache");
     } else {
         if ($be == 'apc') {
             $this->setBackend(new Kwf_Cache_Backend_Apc());
         } else {
             if ($be == 'apcu') {
                 $this->setBackend(new Kwf_Cache_Backend_Apcu());
             } else {
                 //fallback to file backend (NOT recommended!)
                 $this->setBackend(new Kwf_Cache_Backend_File(array('cache_dir' => 'cache/view', 'hashed_directory_level' => 2)));
             }
         }
     }
 }
 public static function countArticles($componentId)
 {
     $authedUser = Kwf_Model_Abstract::getInstance('Users')->getAuthedUser();
     if (!$authedUser) {
         return null;
     }
     $role = 'external';
     if ($authedUser && $authedUser->role == 'external') {
         $role = 'intern';
     }
     $cacheId = 'articleCategoryCount' . $componentId . $role;
     $cnt = Kwf_Cache_Simple::fetch($cacheId);
     if ($cnt === false) {
         $component = Kwf_Component_Data_Root::getInstance()->getComponentById($componentId)->getComponent();
         $cnt = $component->getItemDirectory()->countChildComponents($component->getSelect());
         $ttl = strtotime(date('Y-m-d', strtotime("+1 day"))) - mktime();
         Kwf_Cache_Simple::add($cacheId, $cnt, $ttl);
     }
     return $cnt;
 }
 public function __construct()
 {
     $options = array('lifetime' => null, 'write_control' => false, 'automatic_cleaning_factor' => 0, 'automatic_serialization' => true);
     parent::__construct($options);
     $be = Kwf_Cache_Simple::getBackend();
     if ($be == 'elastiCache') {
         $this->setBackend(new Kwf_Util_Aws_ElastiCache_CacheBackend(array('cacheClusterId' => Kwf_Config::getValue('aws.simpleCacheCluster'), 'compression' => true)));
         //do *not* use cache_namespace for this cache (we don't want to delete it on clear-cache)
     } else {
         if ($be == 'memcache') {
             throw new Kwf_Exception("don't use thru Zend_Cache");
         } else {
             if ($be == 'apc') {
                 $this->setBackend(new Kwf_Cache_Backend_Apc());
             } else {
                 //fallback to file backend (NOT recommended!)
                 $this->setBackend(new Kwf_Cache_Backend_File(array('cache_dir' => 'cache/view', 'hashed_directory_level' => 2)));
             }
         }
     }
 }
 /**
  * destroy of the session
  *
  * @param string $sessionId
  * @return bool
  */
 public function destroy($sessionId)
 {
     $this->_memcache->delete(Kwf_Cache_Simple::getUniquePrefix() . 'sess-' . $sessionId);
     $this->_memcache->delete(Kwf_Cache_Simple::getUniquePrefix() . 'sess-db-' . $sessionId);
     Kwf_Registry::get('db')->query("DELETE FROM kwf_sessions WHERE sessionId=?", $sessionId);
     return true;
 }
 public function clean()
 {
     $be = Kwf_Cache_Simple::getBackend();
     if ($be == 'memcache') {
         $prefix = Kwf_Cache_Simple::getUniquePrefix() . '-media-';
         foreach ($this->_getSecondLevelCache()->getIds() as $id) {
             Kwf_Cache_Simple::getMemcache()->delete($prefix . $id);
         }
     } else {
         if ($be == 'file') {
             //use secondlevel cache only
         } else {
             foreach ($this->_getSecondLevelCache()->getIds() as $id) {
                 Kwf_Cache_Simple::delete('media-' . $id);
             }
         }
     }
     $this->_getSecondLevelCache()->clean();
 }