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'));
 }
 public function load($id)
 {
     $id = self::_processCacheId($id);
     $be = Kwf_Cache_Simple::getBackend();
     if ($be == 'memcache') {
         static $prefix;
         if (!isset($prefix)) {
             $prefix = Kwf_Cache_Simple::getUniquePrefix() . '-media-';
         }
         $ret = Kwf_Cache_Simple::getMemcache()->get($prefix . $id);
     } else {
         if ($be == 'file') {
             //use secondlevel cache only
             $ret = false;
         } else {
             $ret = Kwf_Cache_Simple::fetch('media-' . $id);
         }
     }
     if ($ret === false) {
         $ret = $this->_getSecondLevelCache()->load($id);
         if ($ret && $be != 'file') {
             //first level empty, refill from second level contents
             $metaDatas = $this->_getSecondLevelCache()->getMetadatas($id);
             $ttl = $metaDatas['expire'] ? $metaDatas['expire'] - $metaDatas['mtime'] : 0;
             if ($be == 'memcache') {
                 $flags = is_int($ret) ? null : MEMCACHE_COMPRESSED;
                 Kwf_Cache_Simple::getMemcache()->set($prefix . $id, $ret, $flags, $ttl);
             } else {
                 Kwf_Cache_Simple::add('media-' . $id, $ret, $ttl);
             }
         }
     }
     return $ret;
 }
示例#3
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);
 }
 /**
  * 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 getRow($select)
 {
     if (is_array($select) && count($select) == 1 && isset($select['equals']) && count($select['equals']) == 1 && isset($select['equals'][$this->getPrimaryKey()])) {
         $select = $select['equals'][$this->getPrimaryKey()];
     }
     if (!is_object($select) && !is_array($select)) {
         if (isset($this->_cacheRows[$select])) {
             return $this->_cacheRows[$select];
         }
         $cacheId = $this->_getCacheId($select);
         $success = false;
         $cacheData = Kwf_Cache_Simple::fetch($cacheId, $success);
         if (!$success) {
             $cacheData = array();
             $row = parent::getRow($select);
             if (!$row) {
                 return $row;
             }
             $cacheData[$this->getPrimaryKey()] = $select;
             foreach ($this->_cacheColumns as $c) {
                 $cacheData[$c] = $row->{$c};
             }
             Kwf_Cache_Simple::add($cacheId, $cacheData);
             $this->_cacheRows[$select] = $row;
             return $row;
         }
         $ret = new $this->_rowClass(array('model' => $this, 'cacheData' => $cacheData));
         $this->_cacheRows[$select] = $ret;
         return $ret;
     } else {
         return parent::getRow($select);
     }
 }
示例#6
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;
 }
示例#7
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 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;
 }
 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);
 }
 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;
 }
示例#11
0
 public static function getInstance()
 {
     static $i;
     if (!isset($i)) {
         $t = microtime(true);
         $m = memory_get_usage();
         $cacheId = 'acl';
         $i = Kwf_Cache_Simple::fetch($cacheId);
         if ($i === false) {
             $class = Kwf_Config::getValue('aclClass');
             $i = new $class();
             $i->loadKwcResources();
             Kwf_Cache_Simple::add($cacheId, $i);
             Kwf_Benchmark::subCheckpoint('create Acl', microtime(true) - $t);
         } else {
             Kwf_Benchmark::subCheckpoint('load cached Acl ' . round((memory_get_usage() - $m) / (1024 * 1024), 2) . 'MB', microtime(true) - $t);
         }
     }
     return $i;
 }
示例#12
0
 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;
 }
示例#13
0
 public function getPageByUrl($url, $acceptLanguage, &$exactMatch = true)
 {
     $parsedUrl = parse_url($url);
     if (!isset($parsedUrl['path'])) {
         return null;
     }
     if (!isset($parsedUrl['host'])) {
         throw new Kwf_Exception("Host is missing in url '{$url}'");
     }
     if (substr($parsedUrl['host'], 0, 4) == 'dev.') {
         $parsedUrl['host'] = 'www.' . substr($parsedUrl['host'], 4);
     }
     $cacheUrl = $parsedUrl['host'] . $parsedUrl['path'];
     $cacheId = 'url-' . $cacheUrl;
     if ($page = Kwf_Cache_Simple::fetch($cacheId)) {
         $exactMatch = true;
         $ret = Kwf_Component_Data::kwfUnserialize($page);
     } else {
         $path = $this->getComponent()->formatPath($parsedUrl);
         if (is_null($path)) {
             return null;
         }
         $baseUrl = Kwf_Setup::getBaseUrl();
         if ($baseUrl) {
             if (substr($path, 0, strlen($baseUrl)) != $baseUrl) {
                 return null;
             } else {
                 $path = substr($path, strlen($baseUrl));
             }
         }
         $path = trim($path, '/');
         $ret = $this->getComponent()->getPageByUrl($path, $acceptLanguage);
         if ($ret && rawurldecode($ret->url) == $parsedUrl['path']) {
             //nur cachen wenn kein redirect gemacht wird
             $exactMatch = true;
             if ($ret->isVisible()) {
                 Kwf_Cache_Simple::add($cacheId, $ret->kwfSerialize());
                 Kwf_Component_Cache::getInstance()->getModel('url')->import(Kwf_Model_Abstract::FORMAT_ARRAY, array(array('url' => $cacheUrl, 'page_id' => $ret->componentId, 'expanded_page_id' => $ret->getExpandedComponentId())), array('replace' => true, 'skipModelObserver' => true));
             }
         } else {
             $exactMatch = false;
         }
     }
     return $ret;
 }
示例#14
0
 public function onFavouriteRemove(Kwf_Events_Event_Row_Abstract $event)
 {
     $favourite = $event->row;
     $cacheIdUser = '******' . $favourite->user_id;
     $cacheUser = Kwf_Cache_Simple::fetch($cacheIdUser, $success);
     if ($success) {
         Kwf_Cache_Simple::delete($cacheIdUser);
         $key = array_search($favourite->component_id, $cacheUser);
         unset($cacheUser[$key]);
         Kwf_Cache_Simple::add($cacheIdUser, $cacheUser);
     }
 }
示例#15
0
 protected function _getPageIds($parentData, $select)
 {
     if (!$parentData && ($p = $select->getPart(Kwf_Component_Select::WHERE_CHILD_OF))) {
         if ($p->getPage()) {
             $p = $p->getPage();
         }
         $parentData = $p;
     }
     $pageIds = array();
     if ($parentData && !$select->hasPart(Kwf_Component_Select::WHERE_ID)) {
         // diese Abfragen sind implizit recursive=true
         $parentId = $parentData->dbId;
         if ($select->getPart(Kwf_Component_Select::WHERE_HOME)) {
             $s = new Kwf_Model_Select();
             $s->whereEquals('is_home', true);
             $s->whereEquals('parent_subroot_id', $parentData->getSubroot()->dbId);
             //performance to look only in subroot - correct filterting done below
             Kwf_Benchmark::count('GenPage::query', 'home');
             $rows = $this->_getModel()->export(Kwf_Model_Interface::FORMAT_ARRAY, $s, array('columns' => array('id')));
             $homePages = array();
             foreach ($rows as $row) {
                 $homePages[] = $row['id'];
             }
             foreach ($homePages as $pageId) {
                 $pd = $this->_getPageData($pageId);
                 if (substr($pd['parent_id'], 0, strlen($parentId)) == $parentId) {
                     $pageIds[] = $pageId;
                     continue;
                 }
                 foreach ($pd['parent_ids'] as $pageParentId) {
                     if ($pageParentId == $parentId) {
                         $pageIds[] = $pageId;
                         break;
                     }
                 }
             }
         } else {
             if ($select->hasPart(Kwf_Component_Select::WHERE_FILENAME)) {
                 $filename = $select->getPart(Kwf_Component_Select::WHERE_FILENAME);
                 $cacheId = 'pcFnIds-' . $parentId . '-' . $filename;
                 $pageIds = Kwf_Cache_Simple::fetch($cacheId);
                 if ($pageIds === false) {
                     $s = new Kwf_Model_Select();
                     $s->whereEquals('filename', $filename);
                     if (is_numeric($parentId)) {
                         $s->whereEquals('parent_id', $parentId);
                     } else {
                         $s->where(new Kwf_Model_Select_Expr_Like('parent_id', $parentId . '%'));
                     }
                     Kwf_Benchmark::count('GenPage::query', 'filename');
                     $rows = $this->_getModel()->export(Kwf_Model_Interface::FORMAT_ARRAY, $s, array('columns' => array('id')));
                     $pageIds = array();
                     foreach ($rows as $row) {
                         $pageIds[] = $row['id'];
                     }
                     Kwf_Cache_Simple::add($cacheId, $pageIds);
                 }
             } else {
                 if ($select->hasPart(Kwf_Component_Select::WHERE_COMPONENT_CLASSES)) {
                     $selectClasses = $select->getPart(Kwf_Component_Select::WHERE_COMPONENT_CLASSES);
                     $keys = array();
                     foreach ($selectClasses as $selectClass) {
                         $key = array_search($selectClass, $this->_settings['component']);
                         if ($key) {
                             $keys[] = $key;
                         }
                     }
                     $s = new Kwf_Model_Select();
                     $s->whereEquals('component', array_unique($keys));
                     if (is_numeric($parentId)) {
                         $s->whereEquals('parent_id', $parentId);
                     } else {
                         $s->where(new Kwf_Model_Select_Expr_Like('parent_id', $parentId . '%'));
                     }
                     Kwf_Benchmark::count('GenPage::query', 'component');
                     $rows = $this->_getModel()->export(Kwf_Model_Interface::FORMAT_ARRAY, $s, array('columns' => array('id')));
                     foreach ($rows as $row) {
                         $pageIds[] = $row['id'];
                     }
                 } else {
                     $pageIds = $this->_getChildPageIds($parentId);
                 }
             }
         }
     } else {
         $pagesSelect = new Kwf_Model_Select();
         if ($id = $select->getPart(Kwf_Component_Select::WHERE_ID)) {
             //query only by id, no db query required
             $pageIds = array($id);
             if ($sr = $select->getPart(Kwf_Component_Select::WHERE_SUBROOT)) {
                 $pd = $this->_getPageData($id);
                 if ($pd['parent_subroot_id'] != $sr[0]->dbId) {
                     $pageIds = array();
                 }
             }
             if ($pageIds && $select->hasPart(Kwf_Component_Select::WHERE_COMPONENT_CLASSES)) {
                 $selectClasses = $select->getPart(Kwf_Component_Select::WHERE_COMPONENT_CLASSES);
                 $keys = array();
                 foreach ($selectClasses as $selectClass) {
                     $key = array_search($selectClass, $this->_settings['component']);
                     if ($key && !in_array($key, $keys)) {
                         $keys[] = $key;
                     }
                 }
                 $pd = $this->_getPageData($id);
                 if (!in_array($pd['component'], $keys)) {
                     $pageIds = array();
                 }
             }
             if ($pageIds && $select->getPart(Kwf_Component_Select::WHERE_HOME)) {
                 $pd = $this->_getPageData($id);
                 if (!$pd['is_home']) {
                     $pageIds = array();
                 }
             }
         } else {
             $benchmarkType = '';
             if ($select->hasPart(Kwf_Component_Select::WHERE_SUBROOT)) {
                 $subroot = $select->getPart(Kwf_Component_Select::WHERE_SUBROOT);
                 $subroot = $subroot[0];
                 $pagesSelect->whereEquals('parent_subroot_id', $subroot->dbId);
                 $benchmarkType .= 'subroot ';
             }
             if ($select->getPart(Kwf_Component_Select::WHERE_HOME)) {
                 $pagesSelect->whereEquals('is_home', true);
                 $benchmarkType .= 'home ';
             }
             if ($id = $select->getPart(Kwf_Component_Select::WHERE_ID)) {
                 $pagesSelect->whereEquals('id', $id);
                 $benchmarkType .= 'id ';
             }
             if ($select->hasPart(Kwf_Component_Select::WHERE_COMPONENT_CLASSES)) {
                 $selectClasses = $select->getPart(Kwf_Component_Select::WHERE_COMPONENT_CLASSES);
                 $keys = array();
                 foreach ($selectClasses as $selectClass) {
                     $key = array_search($selectClass, $this->_settings['component']);
                     if ($key && !in_array($key, $keys)) {
                         $keys[] = $key;
                     }
                 }
                 $pagesSelect->whereEquals('component', $keys);
                 $benchmarkType .= 'component ';
             }
             Kwf_Benchmark::count('GenPage::query', "noparent(" . trim($benchmarkType) . ")");
             $rows = $this->_getModel()->export(Kwf_Model_Interface::FORMAT_ARRAY, $pagesSelect, array('columns' => array('id')));
             $pageIds = array();
             foreach ($rows as $row) {
                 $pageIds[] = $row['id'];
             }
         }
         if ($parentData) {
             $parentId = $parentData->dbId;
             foreach ($pageIds as $k => $pageId) {
                 $match = false;
                 $pd = $this->_getPageData($pageId);
                 if (!$pd) {
                     continue;
                 }
                 if (substr($pd['parent_id'], 0, strlen($parentId)) == $parentId) {
                     $match = true;
                 }
                 if (!$match) {
                     foreach ($pd['parent_ids'] as $pageParentId) {
                         if ($pageParentId == $parentId) {
                             $match = true;
                             break;
                         }
                     }
                 }
                 if (!$match) {
                     unset($pageIds[$k]);
                 }
             }
         }
     }
     return $pageIds;
 }
示例#16
0
 public static function getOutput($class, $id, $type)
 {
     $cacheId = 'media-isvalid-' . self::createCacheId($class, $id, $type);
     if (!Kwf_Cache_Simple::fetch($cacheId)) {
         $classWithoutDot = strpos($class, '.') ? substr($class, 0, strpos($class, '.')) : $class;
         if (!Kwf_Loader::isValidClass($classWithoutDot)) {
             throw new Kwf_Exception_NotFound();
         }
         $isValid = Kwf_Media_Output_IsValidInterface::VALID;
         if (is_instance_of($classWithoutDot, 'Kwf_Media_Output_IsValidInterface')) {
             $isValid = call_user_func(array($classWithoutDot, 'isValidMediaOutput'), $id, $type, $class);
             if ($isValid == Kwf_Media_Output_IsValidInterface::INVALID) {
                 throw new Kwf_Exception_NotFound();
             } else {
                 if ($isValid == Kwf_Media_Output_IsValidInterface::ACCESS_DENIED) {
                     throw new Kwf_Exception_AccessDenied();
                 } else {
                     if ($isValid == Kwf_Media_Output_IsValidInterface::VALID) {
                     } else {
                         if ($isValid == Kwf_Media_Output_IsValidInterface::VALID_DONT_CACHE) {
                         } else {
                             throw new Kwf_Exception("unknown isValidMediaOutput return value");
                         }
                     }
                 }
             }
         }
         if ($isValid != Kwf_Media_Output_IsValidInterface::VALID_DONT_CACHE) {
             Kwf_Cache_Simple::add($cacheId, true, 60 * 60);
         }
     }
     Zend_Session::writeClose();
     $output = self::_getOutputWithoutCheckingIsValid($class, $id, $type);
     return $output;
 }
 /**
  * Helper function that can be used in Component implementing Kwf_Media_Output_IsValidInterface
  * to check if the component is visible to the current user
  */
 public static function isValid($id)
 {
     $writeCache = false;
     $cacheId = 'media-isvalid-component-' . $id;
     $plugins = Kwf_Cache_Simple::fetch($cacheId, $success);
     if ($success) {
         //success means it's VALID and we successfully fetched the $plugins
         $ret = Kwf_Media_Output_IsValidInterface::VALID;
     } else {
         $ret = Kwf_Media_Output_IsValidInterface::VALID;
         $c = Kwf_Component_Data_Root::getInstance()->getComponentById($id);
         if (!$c) {
             $c = Kwf_Component_Data_Root::getInstance()->getComponentById($id, array('ignoreVisible' => true));
             if (!$c) {
                 return Kwf_Media_Output_IsValidInterface::INVALID;
             }
             if (Kwf_Component_Data_Root::getShowInvisible()) {
                 //preview im frontend
                 $ret = Kwf_Media_Output_IsValidInterface::VALID_DONT_CACHE;
             } else {
                 if (Kwf_Registry::get('acl')->isAllowedComponentById($id, $c->componentClass, Kwf_Registry::get('userModel')->getAuthedUser())) {
                     //paragraphs preview in backend
                     $ret = Kwf_Media_Output_IsValidInterface::VALID_DONT_CACHE;
                 } else {
                     if (Kwf_Registry::get('acl')->isAllowedUser(Kwf_Registry::get('userModel')->getAuthedUser(), 'kwf_component_preview', 'view')) {
                         //perview user in frontend
                         $ret = Kwf_Media_Output_IsValidInterface::VALID_DONT_CACHE;
                     } else {
                         return Kwf_Media_Output_IsValidInterface::ACCESS_DENIED;
                     }
                 }
             }
         }
         //$ret can be VALID or VALID_DONT_CACHE at this point
         $plugins = array();
         $onlyInherit = false;
         while ($c) {
             $p = Kwc_Abstract::getSetting($c->componentClass, 'pluginsInherit');
             if (!$onlyInherit) {
                 $p = array_merge($p, Kwc_Abstract::getSetting($c->componentClass, 'plugins'));
             }
             foreach ($p as $plugin) {
                 if (is_instance_of($plugin, 'Kwf_Component_Plugin_Interface_Login')) {
                     $plugins[] = array('plugin' => $plugin, 'id' => $c->componentId);
                 }
             }
             if ($c->isPage) {
                 $onlyInherit = true;
             }
             $c = $c->parent;
         }
         if ($ret == Kwf_Media_Output_IsValidInterface::VALID) {
             //only cache VALID, VALID_DONT_CACHE can't be cached
             $writeCache = true;
         }
     }
     foreach ($plugins as $p) {
         $plugin = $p['plugin'];
         $plugin = new $plugin($p['id']);
         if ($plugin->isLoggedIn()) {
             $ret = Kwf_Media_Output_IsValidInterface::VALID_DONT_CACHE;
         } else {
             $c = Kwf_Component_Data_Root::getInstance()->getComponentById($id);
             $userModel = Kwf_Registry::get('userModel');
             if (Kwf_Registry::get('acl')->isAllowedComponentById($id, $c->componentClass, $userModel ? $userModel->getAuthedUser() : null)) {
                 //allow preview in backend always
                 $ret = Kwf_Media_Output_IsValidInterface::VALID_DONT_CACHE;
             } else {
                 $ret = Kwf_Media_Output_IsValidInterface::ACCESS_DENIED;
                 break;
             }
         }
     }
     if ($writeCache && $ret == Kwf_Media_Output_IsValidInterface::VALID_DONT_CACHE) {
         //only cache VALID_DONT_CACHE, not VALID as it will be cached in Kwf_Media::getOutput
         //this cache doesn't need to be cleared, because of it's lifetime
         Kwf_Cache_Simple::add($cacheId, $plugins, 60 * 60 - 1);
         //one second less than isValid cache in Kwf_Media
     }
     return $ret;
 }