[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/Cache/Controller/ -> OutputController.php (source)

   1  <?php
   2  /**
   3   * Joomla! Content Management System
   4   *
   5   * @copyright  (C) 2007 Open Source Matters, Inc. <https://www.joomla.org>
   6   * @license    GNU General Public License version 2 or later; see LICENSE.txt
   7   */
   8  
   9  namespace Joomla\CMS\Cache\Controller;
  10  
  11  \defined('JPATH_PLATFORM') or die;
  12  
  13  use Joomla\CMS\Cache\CacheController;
  14  
  15  /**
  16   * Joomla Cache output type object
  17   *
  18   * @since  1.7.0
  19   */
  20  class OutputController extends CacheController
  21  {
  22      /**
  23       * Cache data ID
  24       *
  25       * @var    string
  26       * @since  1.7.0
  27       */
  28      protected $_id;
  29  
  30      /**
  31       * Cache data group
  32       *
  33       * @var    string
  34       * @since  1.7.0
  35       */
  36      protected $_group;
  37  
  38      /**
  39       * Get stored cached data by ID and group
  40       *
  41       * @param   string  $id     The cache data ID
  42       * @param   string  $group  The cache data group
  43       *
  44       * @return  mixed  Boolean false on no result, cached object otherwise
  45       *
  46       * @since   1.7.0
  47       */
  48  	public function get($id, $group = null)
  49      {
  50          $data = $this->cache->get($id, $group);
  51  
  52          if ($data === false)
  53          {
  54              $locktest = $this->cache->lock($id, $group);
  55  
  56              // If locklooped is true try to get the cached data again; it could exist now.
  57              if ($locktest->locked === true && $locktest->locklooped === true)
  58              {
  59                  $data = $this->cache->get($id, $group);
  60              }
  61  
  62              if ($locktest->locked === true)
  63              {
  64                  $this->cache->unlock($id, $group);
  65              }
  66          }
  67  
  68          // Check again because we might get it from second attempt
  69          if ($data !== false)
  70          {
  71              // Trim to fix unserialize errors
  72              $data = unserialize(trim($data));
  73          }
  74  
  75          return $data;
  76      }
  77  
  78      /**
  79       * Store data to cache by ID and group
  80       *
  81       * @param   mixed    $data        The data to store
  82       * @param   string   $id          The cache data ID
  83       * @param   string   $group       The cache data group
  84       * @param   boolean  $wrkarounds  True to use wrkarounds
  85       *
  86       * @return  boolean  True if cache stored
  87       *
  88       * @since   1.7.0
  89       */
  90  	public function store($data, $id, $group = null, $wrkarounds = true)
  91      {
  92          $locktest = $this->cache->lock($id, $group);
  93  
  94          if ($locktest->locked === false && $locktest->locklooped === true)
  95          {
  96              // We can not store data because another process is in the middle of saving
  97              return false;
  98          }
  99  
 100          $result = $this->cache->store(serialize($data), $id, $group);
 101  
 102          if ($locktest->locked === true)
 103          {
 104              $this->cache->unlock($id, $group);
 105          }
 106  
 107          return $result;
 108      }
 109  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer