public function setItem(string $key, $value, $ttl = 0): bool
    {
        if (
            !$this->adapter instanceof iAdapter
            ||
            !$this->serializer instanceof iSerializer
        ) {
            return false;
        }

        $storeKey = $this->calculateStoreKey($key);
        $serialized = $this->serializer->serialize($value);

        // update static-cache, if it's exists
        if (\array_key_exists($storeKey, self::$STATIC_CACHE)) {
            self::$STATIC_CACHE[$storeKey] = $value;
        }

        if ($ttl) {
            if ($ttl instanceof \DateInterval) {
                // Converting to a TTL in seconds
                /** @noinspection PhpUnhandledExceptionInspection */
                $ttl = (new \DateTimeImmutable('now'))->add($ttl)->getTimestamp() - \time();
            }

            // always cache the TTL time, maybe we need this later ...
            self::$STATIC_CACHE_EXPIRE[$storeKey] = ($ttl ? (int) $ttl + \time() : 0);

            return $this->adapter->setExpired($storeKey, $serialized, $ttl);
        }

        return $this->adapter->set($storeKey, $serialized);
    }
public function setItem(string $key, $value, $ttl = 0): bool
    {
        if (
            !$this->adapter instanceof iAdapter
            ||
            !$this->serializer instanceof iSerializer
        ) {
            return false;
        }

        $storeKey = $this->calculateStoreKey($key);
        $serialized = $this->serializer->serialize($value);

        // update static-cache, if it's exists
        if (\array_key_exists($storeKey, self::$STATIC_CACHE)) {
            self::$STATIC_CACHE[$storeKey] = $value;
        }

        if ($ttl) {
            if ($ttl instanceof \DateInterval) {
                // Converting to a TTL in seconds
                /** @noinspection PhpUnhandledExceptionInspection */
                $ttl = (new \DateTimeImmutable('now'))->add($ttl)->getTimestamp() - \time();
            }

            // always cache the TTL time, maybe we need this later ...
            self::$STATIC_CACHE_EXPIRE[$storeKey] = ($ttl ? (int) $ttl + \time() : 0);

            return $this->adapter->setExpired($storeKey, $serialized, $ttl);
        }

        return $this->adapter->set($storeKey, $serialized);
    }
public function setItem ( string $ key , $ value , $ ttl = 0 ) : bool { if ( ! $ this -> adapter instanceof iAdapter || ! $ this -> serializer instanceof iSerializer ) { return false ; } $ storeKey = $ this -> calculateStoreKey ( $ key ) ; $ serialized = $ this -> serializer -> serialize ( $ value ) ; // update static-cache, if it's exists if ( \ array_key_exists ( $ storeKey , self :: $ STATIC_CACHE ) ) { self :: $ STATIC_CACHE [ $ storeKey ] = $ value ; } if ( $ ttl ) { if ( $ ttl instanceof \ DateInterval ) { // Converting to a TTL in seconds /** @noinspection PhpUnhandledExceptionInspection */ $ ttl = ( new \ DateTimeImmutable ( 'now' ) ) -> add ( $ ttl ) -> getTimestamp ( ) - \ time ( ) ; } // always cache the TTL time, maybe we need this later ... self :: $ STATIC_CACHE_EXPIRE [ $ storeKey ] = ( $ ttl ? ( int ) $ ttl + \ time ( ) : 0 ) ; return $ this -> adapter -> setExpired ( $ storeKey , $ serialized , $ ttl ) ; } return $ this -> adapter -> set ( $ storeKey , $ serialized ) ; }
Set cache-item by key => value + ttl.

@param string                 $key
@param mixed                  $value
@param \DateInterval|int|null $ttl

@throws \InvalidArgumentException

@return bool
Set cache - item by key = > value + ttl .