protected function getOptions() { // Initialize variables. $options = array(); // Convert to name => name array. foreach (MCache::getStores() as $store) { $options[] = MHtml::_('select.option', $store, MText::_('MLIB_FORM_VALUE_CACHE_' . $store), 'value', 'text'); } $options = array_merge(parent::getOptions(), $options); return $options; }
/** * Deleta o valor cacheado * @param string $group * @param string $id */ public static function delete($group, $id) { DCache::delete($group, $id); MCache::delete($group, $id); }
public static function getCache($group = '', $handler = 'callback', $storage = null) { $hash = md5($group . $handler . $storage); if (isset(self::$cache[$hash])) { return self::$cache[$hash]; } $handler = $handler == 'function' ? 'callback' : $handler; $options = array('defaultgroup' => $group); if (isset($storage)) { $options['storage'] = $storage; } $cache = MCache::getInstance($handler, $options); self::$cache[$hash] = $cache; return self::$cache[$hash]; }
public function getBuffer($type = null, $name = null, $attribs = array()) { // If no type is specified, return the whole buffer if ($type === null) { return parent::$_buffer; } $result = null; if (isset(parent::$_buffer[$type][$name])) { return parent::$_buffer[$type][$name]; } // If the buffer has been explicitly turned off don't display or attempt to render if ($result === false) { return null; } $renderer = $this->loadRenderer($type); if ($this->_caching == true && $type == 'modules') { $cache = MFactory::getCache('com_modules', ''); $hash = md5(serialize(array($name, $attribs, $result, $renderer))); $cbuffer = $cache->get('cbuffer_' . $type); if (isset($cbuffer[$hash])) { return MCache::getWorkarounds($cbuffer[$hash], array('mergehead' => 1)); } else { $options = array(); $options['nopathway'] = 1; $options['nomodules'] = 1; $options['modulemode'] = 1; $this->setBuffer($renderer->render($name, $attribs, $result), $type, $name); $data = parent::$_buffer[$type][$name]; $tmpdata = MCache::setWorkarounds($data, $options); $cbuffer[$hash] = $tmpdata; $cache->store($cbuffer, 'cbuffer_' . $type); } } else { $this->setBuffer($renderer->render($name, $attribs, $result), $type, $name); } return parent::$_buffer[$type][$name]; }
protected function _makeId() { return MCache::makeId(); }
protected function cleanCache($group = null, $client_id = 0) { // Initialise variables; $conf = MFactory::getConfig(); $dispatcher = MDispatcher::getInstance(); $options = array('defaultgroup' => $group ? $group : (isset($this->option) ? $this->option : MRequest::getCmd('option')), 'cachebase' => MPATH_CACHE); $cache = MCache::getInstance('callback', $options); $cache->clean(); // Trigger the onContentCleanCache event. $dispatcher->trigger($this->event_clean_cache, $options); }
public function get($callback, $args = array(), $id = false, $wrkarounds = false, $woptions = array()) { if (is_array($callback)) { // We have a standard php callback array -- do nothing } elseif (strstr($callback, '::')) { list($class, $method) = explode('::', $callback); $callback = array(trim($class), trim($method)); } elseif (strstr($callback, '->')) { list($object_123456789, $method) = explode('->', $callback); global ${$object_123456789}; $callback = array(${$object_123456789}, $method); } else { // We have just a standard function -- do nothing } if (!$id) { $id = $this->_makeId($callback, $args); } $data = false; $data = $this->cache->get($id); $locktest = new stdClass(); $locktest->locked = null; $locktest->locklooped = null; if ($data === false) { $locktest = $this->cache->lock($id); if ($locktest->locked == true && $locktest->locklooped == true) { $data = $this->cache->get($id); } } $coptions = array(); if ($data !== false) { $cached = unserialize(trim($data)); $coptions['mergehead'] = isset($woptions['mergehead']) ? $woptions['mergehead'] : 0; $output = $wrkarounds == false ? $cached['output'] : MCache::getWorkarounds($cached['output'], $coptions); $result = $cached['result']; if ($locktest->locked == true) { $this->cache->unlock($id); } } else { if (!is_array($args)) { $Args = !empty($args) ? array(&$args) : array(); } else { $Args =& $args; } if ($locktest->locked == false) { $locktest = $this->cache->lock($id); } if (isset($woptions['modulemode'])) { $document = MFactory::getDocument(); $coptions['modulemode'] = $woptions['modulemode']; $coptions['headerbefore'] = $document->getHeadData(); } else { $coptions['modulemode'] = 0; } ob_start(); ob_implicit_flush(false); $result = call_user_func_array($callback, $Args); $output = ob_get_contents(); ob_end_clean(); $cached = array(); $coptions['nopathway'] = isset($woptions['nopathway']) ? $woptions['nopathway'] : 1; $coptions['nohead'] = isset($woptions['nohead']) ? $woptions['nohead'] : 1; $coptions['nomodules'] = isset($woptions['nomodules']) ? $woptions['nomodules'] : 1; $cached['output'] = $wrkarounds == false ? $output : MCache::setWorkarounds($output, $coptions); $cached['result'] = $result; $this->cache->store(serialize($cached), $id); if ($locktest->locked == true) { $this->cache->unlock($id); } } echo $output; return $result; }
public function flush() { // empty cache MCache::instance()->delete_all(); // back to start url::redirect('cormdemo/index'); }
protected function _makeId(&$view, $method) { return md5(serialize(array(MCache::makeId(), get_class($view), $method))); }
/** * Handles retrieval of all model values, relationships, and metadata. * * @param string column name * @return mixed */ public function __get($column) { if (array_key_exists($column, $this->object)) { return $this->object[$column]; } elseif (isset($this->related[$column])) { return $this->related[$column]; } elseif ($column === 'primary_key_value') { return $this->object[$this->primary_key]; } elseif ($column === 'db') { // lazy loading of DB if (!is_object($this->_db)) { $this->_db = Database::instance($this->_db); } return $this->_db; } elseif ($column === 'cache') { // lazy loading of cache if (!is_object($this->_cache)) { $this->_cache = MCache::instance($this->_cache); } return $this->_cache; } elseif (isset($this->sets[$column])) { // custom set $object_name = $this->sets[$column]['object_name']; $id_set = $this->get_relations($column); // custom sets are stored in the related array //return $this->related[$column] = $this->get_set($object_name,$id_set); return $this->related[$column] = new CORM_Iterator($object_name, $id_set); } elseif (in_array($column, $this->has_one) || in_array($column, $this->belongs_to) || in_array($column, $this->has_many) || in_array($column, $this->has_and_belongs_to_many)) { // relationship $object_name = in_array($column, $this->has_many) || in_array($column, $this->has_and_belongs_to_many) ? inflector::singular($column) : $column; $id_set = $this->get_relations($column); //return $this->related[$column] = $this->get_set($object_name,$id_set); return $this->related[$column] = is_array($id_set) ? new CORM_Iterator($object_name, $id_set) : CORM::factory($object_name, $id_set); } elseif (isset($this->ignored_columns[$column])) { return NULL; } elseif (in_array($column, array('object_name', 'object_plural', 'primary_key', 'primary_val', 'table_name', 'table_columns', 'loaded', 'saved', 'has_one', 'belongs_to', 'has_many', 'has_and_belongs_to_many', 'load_with', 'cachable', 'expire'))) { // Model meta information return $this->{$column}; } else { throw new Kohana_Exception('core.invalid_property', $column, get_class($this)); } }
protected function cleanCache($group = null, $client_id = 0) { $conf = MFactory::getConfig(); $dispatcher = MEventDispatcher::getInstance(); $options = array('defaultgroup' => $group ? $group : (isset($this->option) ? $this->option : MFactory::getApplication()->input->get('option')), 'cachebase' => $client_id ? MPATH_ADMINISTRATOR . '/cache' : $conf->get('cache_path', MPATH_SITE . '/cache')); $cache = MCache::getInstance('callback', $options); $cache->clean(); // Trigger the onContentCleanCache event. $dispatcher->trigger($this->event_clean_cache, $options); }