protected function setLifetime(Response $response, $lifetime)
    {
        if ($lifetime >= 0) {
            $date = clone $response->getDate();
            $response
                ->setMaxAge($lifetime)
                ->setExpires($date->modify(sprintf('+%s seconds', $lifetime)));

            if (!$response->headers->hasCacheControlDirective('private')) {
                $response->setPublic()->setSharedMaxAge($lifetime);
            }
        }

        return $this;
    }