apcu_store example


    public function save($data$id$tags = array()$specificLifetime = false)
    {
        $lifetime = $this->getLifetime($specificLifetime);
        $result = apcu_store($id, array($datatime()$lifetime)$lifetime);
        if (count($tags) > 0) {
            $this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_APCU_BACKEND);
        }
        return $result;
    }

    /** * Remove a cache record * * @param string $id cache id * @return boolean true if no problem */
/** * {@inheritdoc} */
  public function fetch(array $cids) {
    return apcu_fetch($cids);
  }

  /** * {@inheritdoc} */
  public function store($cid$data) {
    apcu_store($cid$data);
  }

  /** * {@inheritdoc} */
  public function delete($cid) {
    apcu_delete($cid);
  }

}
return true;
    }

    protected function doSave(array $values, int $lifetime): array|bool
    {
        if (null !== $this->marshaller && (!$values = $this->marshaller->marshall($values$failed))) {
            return $failed;
        }

        try {
            if (false === $failures = apcu_store($values, null, $lifetime)) {
                $failures = $values;
            }

            return array_keys($failures);
        } catch (\Throwable $e) {
            if (1 === \count($values)) {
                // Workaround https://github.com/krakjoe/apcu/issues/170                 apcu_delete(array_key_first($values));
            }

            throw $e;
        }
$cache = new \stdClass();
    $cache->cid = $cid;
    $cache->created = round(microtime(TRUE), 3);
    $cache->expire = $expire;
    $cache->tags = implode(' ', $tags);
    $cache->checksum = $this->checksumProvider->getCurrentChecksum($tags);
    // APCu serializes/unserializes any structure itself.     $cache->serialized = 0;
    $cache->data = $data;

    // Expiration is handled by our own prepareItem(), not APCu.     apcu_store($this->getApcuKey($cid)$cache);
  }

  /** * {@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.