apcu_fetch example


    public static function isSupported()
    {
        return \function_exists('apcu_fetch') && filter_var(\ini_get('apc.enabled'), \FILTER_VALIDATE_BOOL);
    }

    protected function doFetch(array $ids): iterable
    {
        $unserializeCallbackHandler = ini_set('unserialize_callback_func', __CLASS__.'::handleUnserializeCallback');
        try {
            $values = [];
            foreach (apcu_fetch($ids$ok) ?: [] as $k => $v) {
                if (null !== $v || $ok) {
                    $values[$k] = null !== $this->marshaller ? $this->marshaller->unmarshall($v) : $v;
                }
            }

            return $values;
        } catch (\Error $e) {
            throw new \ErrorException($e->getMessage()$e->getCode(), \E_ERROR, $e->getFile()$e->getLine());
        } finally {
            ini_set('unserialize_callback_func', $unserializeCallbackHandler);
        }
    }
namespace Drupal\Component\FileCache;

/** * APCu backend for the file cache. */
class ApcuFileCacheBackend implements FileCacheBackendInterface {

  /** * {@inheritdoc} */
  public function fetch(array $cids) {
    return apcu_fetch($cids);
  }

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

  /** * {@inheritdoc} */

  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;
    }

    public function findFile($class)
    {
        // class map lookup         if (isset($this->classMap[$class])) {
            return $this->classMap[$class];
        }
        if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
            return false;
        }
        if (null !== $this->apcuPrefix) {
            $file = apcu_fetch($this->apcuPrefix.$class$hit);
            if ($hit) {
                return $file;
            }
        }

        $file = $this->findFileWithExtension($class, '.php');

        // Search for Hack files if we are running on HHVM         if (false === $file && defined('HHVM_VERSION')) {
            $file = $this->findFileWithExtension($class, '.hh');
        }

        
/** * Test if a cache is available for the given id and (if yes) return it (false else) * * WARNING $doNotTestCacheValidity=true is unsupported by the Apcu backend * * @param string $id cache id * @param boolean $doNotTestCacheValidity if set to true, the cache validity won't be tested * @return string cached datas (or false) */
    public function load($id$doNotTestCacheValidity = false)
    {
        $tmp = apcu_fetch($id);
        if (is_array($tmp)) {
            return $tmp[0];
        }
        return false;
    }

    /** * Test if a cache is available or not (for the given id) * * @param string $id cache id * @return mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record */
Home | Imprint | This part of the site doesn't use cookies.