当前位置: 首页>>代码示例>>PHP>>正文


PHP JCache::setWorkarounds方法代码示例

本文整理汇总了PHP中JCache::setWorkarounds方法的典型用法代码示例。如果您正苦于以下问题:PHP JCache::setWorkarounds方法的具体用法?PHP JCache::setWorkarounds怎么用?PHP JCache::setWorkarounds使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JCache的用法示例。


在下文中一共展示了JCache::setWorkarounds方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: get

 /**
  * Get the cached view data
  *
  * @param   object   $view        The view object to cache output for
  * @param   string   $method      The method name of the view method to cache output for
  * @param   mixed    $id          The cache data ID
  * @param   boolean  $wrkarounds  True to enable workarounds.
  *
  * @return  boolean  True if the cache is hit (false else)
  *
  * @since   11.1
  */
 public function get($view, $method = 'display', $id = false, $wrkarounds = true)
 {
     // If an id is not given generate it from the request
     if ($id == false) {
         $id = $this->_makeId($view, $method);
     }
     $data = $this->cache->get($id);
     $locktest = new stdClass();
     $locktest->locked = null;
     $locktest->locklooped = null;
     if ($data === false) {
         $locktest = $this->cache->lock($id, null);
         /*
          * If the loop is completed and returned true it means the lock has been set.
          * If looped is true try to get the cached data again; it could exist now.
          */
         if ($locktest->locked == true && $locktest->locklooped == true) {
             $data = $this->cache->get($id);
         }
         // False means that locking is either turned off or maxtime has been exceeded. Execute the view.
     }
     if ($data !== false) {
         $data = unserialize(trim($data));
         if ($wrkarounds === true) {
             echo JCache::getWorkarounds($data);
         } else {
             // No workarounds, so all data is stored in one piece
             echo isset($data) ? $data : null;
         }
         if ($locktest->locked == true) {
             $this->cache->unlock($id);
         }
         return true;
     }
     // No hit so we have to execute the view
     if (method_exists($view, $method)) {
         // If previous lock failed try again
         if ($locktest->locked == false) {
             $locktest = $this->cache->lock($id);
         }
         // Capture and echo output
         ob_start();
         ob_implicit_flush(false);
         $view->{$method}();
         $data = ob_get_clean();
         echo $data;
         /*
          * For a view we have a special case.  We need to cache not only the output from the view, but the state
          * of the document head after the view has been rendered.  This will allow us to properly cache any attached
          * scripts or stylesheets or links or any other modifications that the view has made to the document object
          */
         $cached = $wrkarounds == true ? JCache::setWorkarounds($data) : $data;
         // Store the cache data
         $this->cache->store(serialize($cached), $id);
         if ($locktest->locked == true) {
             $this->cache->unlock($id);
         }
     }
     return false;
 }
开发者ID:adjaika,项目名称:J3Base,代码行数:72,代码来源:view.php

示例2: store

 /**
  * Stop the cache buffer and store the cached data
  *
  * @param   mixed    $data        The data to store
  * @param   string   $id          The cache data id
  * @param   string   $group       The cache data group
  * @param   boolean  $wrkarounds  True to use wrkarounds
  *
  * @return  boolean  True if cache stored
  *
  * @since   11.1
  */
 public function store($data, $id, $group = null, $wrkarounds = true)
 {
     // Get page data from the application object
     if (empty($data)) {
         $data = JFactory::getApplication()->getBody();
     }
     // Get id and group and reset the placeholders
     if (empty($id)) {
         $id = $this->_id;
     }
     if (empty($group)) {
         $group = $this->_group;
     }
     // Only attempt to store if page data exists
     if ($data) {
         if ($wrkarounds) {
             $data = JCache::setWorkarounds($data, array('nopathway' => 1, 'nohead' => 1, 'nomodules' => 1, 'headers' => true));
         }
         if ($this->_locktest->locked == false) {
             $this->_locktest = $this->cache->lock($id, $group);
         }
         $sucess = $this->cache->store(serialize($data), $id, $group);
         if ($this->_locktest->locked == true) {
             $this->cache->unlock($id, $group);
         }
         return $sucess;
     }
     return false;
 }
开发者ID:WineWorld,项目名称:joomlatrialcmbg,代码行数:41,代码来源:page.php

示例3: get

 /**
  * Executes a cacheable callback if not found in cache else returns cached output and result
  *
  * @param   mixed    $callback    Callback or string shorthand for a callback
  * @param   array    $args        Callback arguments
  * @param   mixed    $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);
     }
     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'] : JCache::getWorkarounds($cached['output'], $coptions);
         $result = $cached['result'];
         if ($locktest->locked == true) {
             $this->cache->unlock($id);
         }
     } else {
         if (!is_array($args)) {
             $referenceArgs = !empty($args) ? array(&$args) : array();
         } else {
             $referenceArgs =& $args;
         }
         if ($locktest->locked == false) {
             $locktest = $this->cache->lock($id);
         }
         if (isset($woptions['modulemode']) && $woptions['modulemode'] == 1) {
             $document = JFactory::getDocument();
             $coptions['modulemode'] = 1;
             if (method_exists($document, 'getHeadData')) {
                 $coptions['headerbefore'] = $document->getHeadData();
             }
         } else {
             $coptions['modulemode'] = 0;
         }
         ob_start();
         ob_implicit_flush(false);
         $result = call_user_func_array($callback, $referenceArgs);
         $output = ob_get_clean();
         $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 = array('output' => $wrkarounds == false ? $output : JCache::setWorkarounds($output, $coptions), 'result' => $result);
         // Store the cache data
         $this->cache->store(serialize($cached), $id);
         if ($locktest->locked == true) {
             $this->cache->unlock($id);
         }
     }
     echo $output;
     return $result;
 }
开发者ID:N6REJ,项目名称:joomla-cms,代码行数:92,代码来源:callback.php

示例4: getBuffer

 /**
  * 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  1.0
  */
 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 = JFactory::getCache('com_modules', '');
         $hash = md5(serialize(array($name, $attribs, $result, $renderer)));
         $cbuffer = $cache->get('cbuffer_' . $type);
         if (isset($cbuffer[$hash])) {
             return JCache::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 = JCache::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];
 }
开发者ID:Rikisha,项目名称:proj,代码行数:47,代码来源:document.php

示例5: store

 /**
  * Stop the cache buffer and store the cached data
  *
  * @return	boolean	True if cache stored
  * @since	1.6
  */
 public function store($wrkarounds = true)
 {
     // Get page data from JResponse body
     $data = JResponse::getBody();
     // Get id and group and reset them placeholders
     $id = $this->_id;
     $group = $this->_group;
     $this->_id = null;
     $this->_group = null;
     // Only attempt to store if page data exists
     if ($data) {
         $data = $wrkarounds == false ? $data : JCache::setWorkarounds($data);
         if ($this->_locktest->locked == false) {
             $this->_locktest = $this->cache->lock($id, $group);
         }
         $sucess = $this->cache->store(serialize($data), $id, $group);
         if ($this->_locktest->locked == true) {
             $this->cache->unlock($id, $group);
         }
         return $sucess;
     }
     return false;
 }
开发者ID:akksi,项目名称:jcg,代码行数:29,代码来源:page.php

示例6: get

 /**
  * Executes a cacheable callback if not found in cache else returns cached output and result
  *
  * @param   callable  $callback    Callback or string shorthand for a callback
  * @param   array     $args        Callback arguments
  * @param   mixed     $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())
 {
     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'] : JCache::getWorkarounds($cached['output'], $coptions);
         $result = $cached['result'];
         if ($locktest->locked == true) {
             $this->cache->unlock($id);
         }
     } else {
         if (!is_array($args)) {
             $referenceArgs = !empty($args) ? array(&$args) : array();
         } else {
             $referenceArgs =& $args;
         }
         if ($locktest->locked == false) {
             $locktest = $this->cache->lock($id);
         }
         if (isset($woptions['modulemode']) && $woptions['modulemode'] == 1) {
             $document = JFactory::getDocument();
             $coptions['modulemode'] = 1;
             if (method_exists($document, 'getHeadData')) {
                 $coptions['headerbefore'] = $document->getHeadData();
             }
         } else {
             $coptions['modulemode'] = 0;
         }
         ob_start();
         ob_implicit_flush(false);
         $result = call_user_func_array($callback, $referenceArgs);
         $output = ob_get_clean();
         $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 = array('output' => $wrkarounds == false ? $output : JCache::setWorkarounds($output, $coptions), 'result' => $result);
         // Store the cache data
         $this->cache->store(serialize($cached), $id);
         if ($locktest->locked == true) {
             $this->cache->unlock($id);
         }
     }
     echo $output;
     return $result;
 }
开发者ID:Rai-Ka,项目名称:joomla-cms,代码行数:73,代码来源:callback.php


注:本文中的JCache::setWorkarounds方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。