Esempio n. 1
0
 /**
  * Tests the Joomla\Cache\Cache::__construct method.
  *
  * @return  void
  *
  * @covers  Joomla\Cache\Cache::__construct
  * @covers  Joomla\Cache\Apc::__construct
  * @covers  Joomla\Cache\Memcached::__construct
  * @expectedException  \RuntimeException
  * @since   1.0
  */
 public function test__construct()
 {
     // This checks the default ttl and also that the options registry was initialised.
     $this->assertEquals('900', $this->instance->getOption('ttl'));
     // Throws exception, options is null
     $className = $this->cacheClass;
     new $className(null);
 }
Esempio n. 2
0
 /**
  * Constructor.
  *
  * @param   array  $options  Caching options object.
  *
  * @since   1.0
  * @throws  \RuntimeException
  */
 public function __construct($options = array())
 {
     if (!extension_loaded('wincache') || !is_callable('wincache_ucache_get')) {
         throw new \RuntimeException('WinCache not supported.');
     }
     parent::__construct($options);
 }
Esempio n. 3
0
 /**
  * Constructor.
  *
  * @param   mixed  $options  An options array, or an object that implements \ArrayAccess
  *
  * @since   1.0
  * @throws  \RuntimeException
  */
 public function __construct($options = array())
 {
     if (!extension_loaded('redis') || !class_exists('\\Redis')) {
         throw new \RuntimeException('Redis not supported.');
     }
     parent::__construct($options);
 }
Esempio n. 4
0
 /**
  * Constructor.
  *
  * @param   mixed  $options  An options array, or an object that implements \ArrayAccess
  *
  * @since   1.0
  * @throws  \RuntimeException
  */
 public function __construct($options = array())
 {
     if (!extension_loaded('apc') || !is_callable('apc_fetch')) {
         throw new \RuntimeException('APC not supported.');
     }
     parent::__construct($options);
 }
Esempio n. 5
0
 /**
  * Constructor.
  *
  * @param   mixed  $options  An options array, or an object that implements \ArrayAccess
  *
  * @since   1.0
  * @throws  \RuntimeException
  */
 public function __construct($options = array())
 {
     parent::__construct($options);
     if (!isset($this->options['file.locking'])) {
         $this->options['file.locking'] = true;
     }
     $this->checkFilePath($this->options['file.path']);
 }
 /**
  * Method to get the field options.
  *
  * @return  array    The field option objects.
  *
  * @since   11.1
  */
 protected function getOptions()
 {
     $options = array();
     // Convert to name => name array.
     foreach (Cache::getStores() as $store) {
         $options[] = Html::_('select.option', $store, Text::_('JLIB_FORM_VALUE_CACHE_' . $store), 'value', 'text');
     }
     $options = array_merge(parent::getOptions(), $options);
     return $options;
 }
Esempio n. 7
0
 /**
  * Constructor.
  *
  * @param   mixed  $options  An options array, or an object that implements \ArrayAccess
  *
  * @since   1.0
  * @throws  \RuntimeException
  */
 public function __construct($options = array())
 {
     if (!isset($options['file.locking'])) {
         $options['file.locking'] = true;
     }
     if (!isset($options['file.path'])) {
         throw new \RuntimeException('The file.path option must be set.');
     }
     $this->checkFilePath($options['file.path']);
     parent::__construct($options);
 }
 /**
  * Executes a cacheable callback if not found in cache else returns cached output and result
  *
  * @param   mixed    $callback    Callable or string shorthand for a callback
  * @param   array    $args        Callback arguments
  * @param   string   $id          Cache id
  * @param   boolean  $wrkarounds  True to use wrkarounds
  * @param   array    $woptions    Workaround options
  *
  * @return  mixed  Result of the callback
  *
  * @since   11.1
  */
 public function get($callback, $args = array(), $id = false, $wrkarounds = false, $woptions = array())
 {
     // Normalize callback
     if (is_array($callback)) {
         // We have a standard php callback array -- do nothing
     } elseif (strstr($callback, '::')) {
         // This is shorthand for a static method callback classname::methodname
         list($class, $method) = explode('::', $callback);
         $callback = array(trim($class), trim($method));
     } elseif (strstr($callback, '->')) {
         /*
          * This is a really not so smart way of doing this... we provide this for backward compatability but this
          * WILL! disappear in a future version.  If you are using this syntax change your code to use the standard
          * PHP callback array syntax: <http://php.net/callback>
          *
          * We have to use some silly global notation to pull it off and this is very unreliable
          */
         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) {
         // Generate an ID
         $id = $this->_makeId($callback, $args);
     }
     $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'] : Cache::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']) && $woptions['modulemode'] == 1) {
             $document = Factory::getDocument();
             $coptions['modulemode'] = 1;
             $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 : Cache::setWorkarounds($output, $coptions);
         $cached['result'] = $result;
         // Store the cache data
         $this->cache->store(serialize($cached), $id);
         if ($locktest->locked == true) {
             $this->cache->unlock($id);
         }
     }
     echo $output;
     return $result;
 }
Esempio n. 9
0
 /**
  * Constructor.
  *
  * @param   mixed  $options  An options array, or an object that implements \ArrayAccess
  *
  * @since   1.0
  * @throws  \RuntimeException
  */
 public function __construct($options = array())
 {
     parent::__construct($options);
     $this->db = new \ArrayObject();
 }
 /**
  * Generate a page cache id
  *
  * @return  string  MD5 Hash : page cache id
  *
  * @since   11.1
  * @todo    Discuss whether this should be coupled to a data hash or a request
  * hash ... perhaps hashed with a serialized request
  */
 protected function _makeId()
 {
     return Cache::makeId();
 }
 /**
  * Get the contents of a document include
  *
  * @param   string  $type     The type of renderer
  * @param   string  $name     The name of the element to render
  * @param   array   $attribs  Associative array of remaining attributes.
  *
  * @return  The output of the renderer
  *
  * @since   11.1
  */
 public function getBuffer($type = null, $name = null, $attribs = array())
 {
     // If no type is specified, return the whole buffer
     if ($type === null) {
         return parent::$_buffer;
     }
     $title = isset($attribs['title']) ? $attribs['title'] : null;
     if (isset(parent::$_buffer[$type][$name][$title])) {
         return parent::$_buffer[$type][$name][$title];
     }
     $renderer = $this->loadRenderer($type);
     if ($this->_caching == true && $type == 'modules') {
         $cache = Factory::getCache('com_modules', '');
         $hash = md5(serialize(array($name, $attribs, null, $renderer)));
         $cbuffer = $cache->get('cbuffer_' . $type);
         if (isset($cbuffer[$hash])) {
             return Cache::getWorkarounds($cbuffer[$hash], array('mergehead' => 1));
         } else {
             $options = array();
             $options['nopathway'] = 1;
             $options['nomodules'] = 1;
             $options['modulemode'] = 1;
             $this->setBuffer($renderer->render($name, $attribs, null), $type, $name);
             $data = parent::$_buffer[$type][$name][$title];
             $tmpdata = Cache::setWorkarounds($data, $options);
             $cbuffer[$hash] = $tmpdata;
             $cache->store($cbuffer, 'cbuffer_' . $type);
         }
     } else {
         $this->setBuffer($renderer->render($name, $attribs, null), $type, $name, $title);
     }
     return parent::$_buffer[$type][$name][$title];
 }
 /**
  * Get a cache object
  *
  * Returns the global {@link Cache} object
  *
  * @param   string  $group    The cache group name
  * @param   string  $handler  The handler to use
  * @param   string  $storage  The storage method
  *
  * @return  \Joomla\Cache\Controller object
  *
  * @see     Cache
  */
 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 = Cache::getInstance($handler, $options);
     self::$cache[$hash] = $cache;
     return self::$cache[$hash];
 }
Esempio n. 13
0
 /**
  * Tests the Joomla\Cache\Cache::__construct method.
  *
  * @return  void
  *
  * @covers  Joomla\Cache\Cache::__construct
  * @since   1.0
  */
 public function test__construct()
 {
     // This checks the default ttl and also that the options registry was initialised.
     $this->assertEquals('900', $this->instance->getOption('ttl'));
 }
 /**
  * Generate a view cache id.
  *
  * @param   object  &$view   The view object to cache output for
  * @param   string  $method  The method name to cache for the view object
  *
  * @return  string  MD5 Hash : view cache id
  *
  * @since   11.1
  */
 protected function _makeId(&$view, $method)
 {
     return md5(serialize(array(Cache::makeId(), get_class($view), $method)));
 }