code: 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;
      }
docs: Set max-age, s-maxage and expires headers.
  
  Set $lifetime as < 0 for not set max-age
  Need set Cache-Control public/private before set lifetime
  
  @param Response $response
  @param int $lifetime
  
  @return ResponseConfigurator