src/Psr16MemoryCache.php
public function set($key, $value, $ttl = null)
    {
        \WildWolf\Cache\Validator::validateKey($key);
        \WildWolf\Cache\Validator::validateTtl($ttl);

        if ($ttl instanceof \DateInterval) {
            $expires = new \DateTime();
            $expires->add($ttl);
        } elseif (is_numeric($ttl)) {
            $expires = new \DateTime('now +' . $ttl . ' seconds');
        } else {
            $expires = null;
        }

        if (is_object($value)) {
            $value = clone $value;
        }

        $this->cache[$key] = [$value, $expires];
        return true;
    }
public function set($key, $value, $ttl = null)
    {
        \WildWolf\Cache\Validator::validateKey($key);
        \WildWolf\Cache\Validator::validateTtl($ttl);

        if ($ttl instanceof \DateInterval) {
            $expires = new \DateTime();
            $expires->add($ttl);
        } elseif (is_numeric($ttl)) {
            $expires = new \DateTime('now +' . $ttl . ' seconds');
        } else {
            $expires = null;
        }

        if (is_object($value)) {
            $value = clone $value;
        }

        $this->cache[$key] = [$value, $expires];
        return true;
    }
Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time.

@param string                $key   The key of the item to store.
@param mixed                 $value The value of the item to store, must be serializable.
@param null|int|\DateInterval $ttl  Optional. The TTL value of this item. If no value is sent and
the driver supports TTL then the library may set a default value
for it or let the driver take care of that.

@return bool True on success and false on failure.

@throws \Psr\SimpleCache\InvalidArgumentException
MUST be thrown if the $key string is not a legal value.