use Symfony\Component\HttpFoundation\Response; $response = new Response($content); $response->setTtl(3600); // 3600 seconds = 1 hour
use Symfony\Component\HttpFoundation\Response; $response = new Response($content); $response->setPublic(); $response->setTtl(300); // 300 seconds = 5 minutesIn both examples, we create a new instance of the Response class and pass in the content for the response. We then use the setTtl method to set the amount of time for which the response should be considered fresh. The first example sets the TTL to 1 hour (3600 seconds), while the second example sets it to 5 minutes (300 seconds). In the second example, we also use the setPublic method to indicate that the response can be cached by public (i.e. non-authenticated) clients. Overall, the setTtl method is useful for controlling how long HTTP responses should be cached by clients, which can help improve performance and reduce server load.