public function setMulti(array $objects, callable $objectIndexes, string $listIndex = null): void
    {
        // If objects accounts for more then 20% of our limit, assume it's bulk load and skip saving in-memory
        if ($this->enabled === false || \count($objects) >= $this->limit / 5) {
            return;
        }

        // check if we will reach limit by adding these objects, if so remove old cache
        if (\count($this->cache) + \count($objects) >= $this->limit) {
            $this->vacuum();
        }

        $expiryTime = microtime(true) + $this->ttl;
        // if set add objects to cache on list index (typically a "all" key)
        if ($listIndex) {
            $this->cache[$listIndex] = $objects;
            $this->cacheExpiryTime[$listIndex] = $expiryTime;
            $this->cacheAccessCount[$listIndex] = 0;
        }

        foreach ($objects as $object) {
            // Skip if there are no indexes
            if (!$indexes = $objectIndexes($object)) {
                continue;
            }

            $key = \array_shift($indexes);
            $this->cache[$key] = $object;
            $this->cacheExpiryTime[$key] = $expiryTime;
            $this->cacheAccessCount[$key] = 0;

            foreach ($indexes as $index) {
                $this->cacheIndex[$index] = $key;
            }
        }
    }
public function setMulti(array $objects, callable $objectIndexes, string $listIndex = null): void
    {
        // If objects accounts for more then 20% of our limit, assume it's bulk load and skip saving in-memory
        if ($this->enabled === false || \count($objects) >= $this->limit / 5) {
            return;
        }

        // check if we will reach limit by adding these objects, if so remove old cache
        if (\count($this->cache) + \count($objects) >= $this->limit) {
            $this->vacuum();
        }

        $expiryTime = microtime(true) + $this->ttl;
        // if set add objects to cache on list index (typically a "all" key)
        if ($listIndex) {
            $this->cache[$listIndex] = $objects;
            $this->cacheExpiryTime[$listIndex] = $expiryTime;
            $this->cacheAccessCount[$listIndex] = 0;
        }

        foreach ($objects as $object) {
            // Skip if there are no indexes
            if (!$indexes = $objectIndexes($object)) {
                continue;
            }

            $key = \array_shift($indexes);
            $this->cache[$key] = $object;
            $this->cacheExpiryTime[$key] = $expiryTime;
            $this->cacheAccessCount[$key] = 0;

            foreach ($indexes as $index) {
                $this->cacheIndex[$index] = $key;
            }
        }
    }
public function setMulti ( array $ objects , callable $ objectIndexes , string $ listIndex = null ) : void { // If objects accounts for more then 20% of our limit, assume it's bulk load and skip saving in-memory if ( $ this -> enabled === false || \ count ( $ objects ) >= $ this -> limit / 5 ) { return ; } // check if we will reach limit by adding these objects, if so remove old cache if ( \ count ( $ this -> cache ) + \ count ( $ objects ) >= $ this -> limit ) { $ this -> vacuum ( ) ; } $ expiryTime = microtime ( true ) + $ this -> ttl ; // if set add objects to cache on list index (typically a "all" key) if ( $ listIndex ) { $ this -> cache [ $ listIndex ] = $ objects ; $ this -> cacheExpiryTime [ $ listIndex ] = $ expiryTime ; $ this -> cacheAccessCount [ $ listIndex ] = 0 ; } foreach ( $ objects as $ object ) { // Skip if there are no indexes if ( ! $ indexes = $ objectIndexes ( $ object ) ) { continue ; } $ key = \ array_shift ( $ indexes ) ; $ this -> cache [ $ key ] = $ object ; $ this -> cacheExpiryTime [ $ key ] = $ expiryTime ; $ this -> cacheAccessCount [ $ key ] = 0 ; foreach ( $ indexes as $ index ) { $ this -> cacheIndex [ $ index ] = $ key ; } } }
Set object in in-memory cache.

Should only set Cache hits here!

@param object[] $objects
@param callable $objectIndexes Return array of indexes per object (first argument), must return at least 1 primary index
@param string|null $listIndex Optional index for list of items
Set object in in - memory cache .