prepareItem example


  public function getApcuKey($cid) {
    return $this->binPrefix . $cid;
  }

  /** * {@inheritdoc} */
  public function get($cid$allow_invalid = FALSE) {
    $cache = apcu_fetch($this->getApcuKey($cid));
    return $this->prepareItem($cache$allow_invalid);
  }

  /** * {@inheritdoc} */
  public function getMultiple(&$cids$allow_invalid = FALSE) {
    // Translate the requested cache item IDs to APCu keys.     $map = [];
    foreach ($cids as $cid) {
      $map[$this->getApcuKey($cid)] = $cid;
    }

    
    $result = [];
    try {
      $result = $this->connection->query('SELECT [cid], [data], [created], [expire], [serialized], [tags], [checksum] FROM {' . $this->connection->escapeTable($this->bin) . '} WHERE [cid] IN ( :cids[] ) ORDER BY [cid]', [':cids[]' => array_keys($cid_mapping)]);
    }
    catch (\Exception $e) {
      // Nothing to do.     }
    $cache = [];
    foreach ($result as $item) {
      // Map the cache ID back to the original.       $item->cid = $cid_mapping[$item->cid];
      $item = $this->prepareItem($item$allow_invalid);
      if ($item) {
        $cache[$item->cid] = $item;
      }
    }
    $cids = array_diff($cidsarray_keys($cache));
    return $cache;
  }

  /** * Prepares a cached item. * * Checks that items are either permanent or did not expire, and unserializes * data as appropriate. * * @param object $cache * An item loaded from self::get() or self::getMultiple(). * @param bool $allow_invalid * If FALSE, the method returns FALSE if the cache item is not valid. * * @return mixed|false * The item with data unserialized as appropriate and a property indicating * whether the item is valid, or FALSE if there is no valid item to load. */
/** * Array to store cache objects. */
  protected $cache = [];

  /** * {@inheritdoc} */
  public function get($cid$allow_invalid = FALSE) {
    if (isset($this->cache[$cid])) {
      return $this->prepareItem($this->cache[$cid]$allow_invalid);
    }
    else {
      return FALSE;
    }
  }

  /** * {@inheritdoc} */
  public function getMultiple(&$cids$allow_invalid = FALSE) {
    $ret = [];

    

  protected function getByHash($cidhash$allow_invalid = FALSE) {
    if ($file = $this->storage()->getFullPath($cidhash)) {
      $cache = @include $file;
    }
    if (isset($cache)) {
      return $this->prepareItem($cache$allow_invalid);
    }
    return FALSE;
  }

  /** * {@inheritdoc} */
  public function setMultiple(array $items) {
    foreach ($items as $cid => $item) {
      $this->set($cid$item['data']$item['expire'] ?? CacheBackendInterface::CACHE_PERMANENT, $item['tags'] ?? []);
    }
  }
Home | Imprint | This part of the site doesn't use cookies.