public function save(Kwf_Component_Data $component, $content, $renderer, $type, $value, $tag, $lifetime) { $microtime = $this->_getMicrotime(); // MySQL $data = array('component_id' => (string) $component->componentId, 'db_id' => (string) $component->dbId, 'page_db_id' => (string) $component->getPageOrRoot()->dbId, 'expanded_component_id' => (string) $component->getExpandedComponentId(), 'component_class' => $component->componentClass, 'renderer' => $renderer, 'type' => $type, 'value' => (string) $value, 'tag' => (string) $tag, 'microtime' => $microtime, 'expire' => is_null($lifetime) ? null : time() + $lifetime, 'deleted' => false, 'content' => $content); $options = array('buffer' => true, 'replace' => true, 'skipModelObserver' => true); $this->getModel('cache')->import(Kwf_Model_Abstract::FORMAT_ARRAY, array($data), $options); // APC $cacheId = $this->_getCacheId($component->componentId, $renderer, $type, $value); $ttl = null; if ($lifetime) { $ttl = $lifetime; } Kwf_Component_Cache_Memory::getInstance()->save($content, $cacheId, $ttl, $microtime); return true; }
public function save(Kwf_Component_Data $component, $contents, $renderer, $type, $value, $tag, $lifetime) { $key = self::_getCacheId($component->componentId, $renderer, $type, $value); $setKey = $key; //key that will be stored in sets if ($type == 'fullPage') { $setKey .= ':' . $component->getDomainComponentId() . ':' . $component->url; } $this->_redis->sAdd('viewids:componentid:' . $component->componentId, $setKey); $this->_redis->sAdd('viewids:dbid:' . $component->dbId, $setKey); $this->_redis->sAdd('viewids:pagedbid:' . $component->getPageOrRoot()->dbId, $setKey); $this->_redis->sAdd('viewids:cls:' . $component->componentClass, $setKey); if ($tag) { $this->_redis->sAdd('viewids:tag:' . $tag, $setKey); } $parts = preg_split('/([_\\-])/', $component->getExpandedComponentId(), -1, PREG_SPLIT_DELIM_CAPTURE); $id = ''; foreach ($parts as $part) { $id .= $part; if ($part != '-' && $part != '_' && $id != 'root') { $this->_redis->sAdd('viewids:recexpandedid:' . $id, $setKey); } } $cacheContent = array('contents' => $contents, 'expire' => is_null($lifetime) ? null : time() + $lifetime); if (Kwf_Cache_Simple::getBackend() == 'memcache') { static $prefix; if (!isset($prefix)) { $prefix = Kwf_Cache_Simple::getUniquePrefix() . '-'; } $ret = Kwf_Cache_Simple::getMemcache()->set($prefix . $key, $cacheContent, MEMCACHE_COMPRESSED, $lifetime); } else { if (is_null($lifetime)) { //Set a TTL for view contents http://stackoverflow.com/questions/16370278/how-to-make-redis-choose-lru-eviction-policy-for-only-some-of-the-keys $lifetime = 365 * 24 * 60 * 60; } $ret = $this->_redis->setEx($key, $lifetime, serialize($cacheContent)); } return $ret; }
/** * Returns variables that can be used in Master.tpl * @param e.g. for accessing recipient in Mail_Renderer * @return array */ public function getMasterTemplateVars(Kwf_Component_Data $innerComponent, Kwf_Component_Renderer_Abstract $renderer) { $ret = array(); $ret['component'] = $innerComponent; $ret['data'] = $innerComponent; $ret['pageLanguage'] = $innerComponent->getLanguage(); $ret['boxes'] = array(); foreach ($innerComponent->getPageOrRoot()->getChildBoxes() as $box) { $ret['boxes'][$box->box] = $box; } $ret['multiBoxes'] = array(); foreach ($innerComponent->getPageOrRoot()->getRecursiveChildComponents(array('multiBox' => true)) as $box) { $ret['multiBoxes'][$box->box][] = $box; } //sort by priority foreach ($ret['multiBoxes'] as $box => $components) { usort($ret['multiBoxes'][$box], array('Kwf_Component_View_Helper_ComponentWithMaster', '_sortByPriority')); } $up = Kwf_Config::getValue('application.uniquePrefix'); if (!$up) { $ret['bemClass'] = ''; } else { $ret['bemClass'] = Kwf_Component_Abstract::formatRootElementClass($this->getData()->componentClass, '') . 'Master__'; } $ret['rootElementClass'] = 'kwfUp-frontend ' . Kwf_Component_Abstract::formatRootElementClass($this->getData()->componentClass, '') . 'Master'; return $ret; }
/** * Returns variables that can be used in Master.tpl * @param e.g. for accessing recipient in Mail_Renderer * @return array */ public function getMasterTemplateVars(Kwf_Component_Data $innerComponent, Kwf_Component_Renderer_Abstract $renderer) { $ret = array(); $ret['component'] = $innerComponent; $ret['data'] = $innerComponent; $ret['boxes'] = array(); foreach ($innerComponent->getPageOrRoot()->getChildBoxes() as $box) { $ret['boxes'][$box->box] = $box; } $ret['multiBoxes'] = array(); foreach ($innerComponent->getPageOrRoot()->getRecursiveChildComponents(array('multiBox' => true)) as $box) { $ret['multiBoxes'][$box->box][] = $box; } //sort by priority foreach ($ret['multiBoxes'] as $box => $components) { usort($ret['multiBoxes'][$box], array('Kwf_Component_View_Helper_ComponentWithMaster', '_sortByPriority')); } $ret['cssClass'] = 'frontend'; $cls = Kwc_Abstract::getSetting($this->getData()->componentClass, 'processedCssClass'); foreach (explode(' ', $cls) as $i) { $i = 'kwfup-master' . ucfirst($i); $ret['cssClass'] .= ' ' . $i; } return $ret; }