Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

make the cache ttl compatible with Symfony #106

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

nanofelis
Copy link

@nanofelis nanofelis commented Jun 8, 2022

The cache used in the FirebaseJwtAdapter is not compatible with symfony/cache because it uses a Carbon date for the cache item TTL but Symfony only accepts an integer or a DateInterval.

https://github.com/symfony/cache/blob/364fc90734230d936ac2db8e897cc03ec8497bbb/CacheItem.php#L90

    public function expiresAfter($time): self
    {
        if (null === $time) {
            $this->expiry = null;
        } elseif ($time instanceof \DateInterval) {
            $this->expiry = microtime(true) + \DateTime::createFromFormat('U', 0)->add($time)->format('U.u');
        } elseif (\is_int($time)) {
            $this->expiry = $time + microtime(true);
        } else {
            throw new InvalidArgumentException(sprintf('Expiration date must be an integer, a DateInterval or null, "%s" given.', get_debug_type($time)));
        }

        return $this;
    }

So we get the following exception when setting the TTL:

{
    class: "Symfony\\Component\\Cache\\Exception\\InvalidArgumentException"
    detail: "Expiration date must be an integer, a DateInterval or null, \"Carbon\\Carbon\" given."
}

Issue : #107

Copy link

@selvaramj selvaramj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i tried this one in my local, its working fine with symfony, please validate & release this code.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants