11.08.2017 Views

codebright

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Responses 67<br />

object actually inherits most of its content from the Response object belonging to the Symfony<br />

HTTPFoundation component.<br />

What this means is that if we take a look at the API for the Symfony response object, suddenly we<br />

have access to a whole heap of extra methods that aren’t covered in the Laravel docs! Holy smokes!<br />

Now that I have given away this secret, there’s nothing to stop you from becoming a Laravel master!<br />

The API documentation for the Symfony Response object can be found here¹⁹. If you look at the page<br />

you will notice that the class has an attribute called $headers. That’s right! That’s the collection of<br />

headers we were using only a minute ago.<br />

Since the Laravel response object inherits from this one, feel free to use any of the methods you see<br />

in the Symfony API documentation. For example, let’s have a look at the setTtl() method. What<br />

does the API say?<br />

public Response setTtl(**integer $seconds**)<br />

Sets the response’s time-to-live for shared caches. This method adjusts the Cache-Control/s-maxage<br />

directive.<br />

Parameters:<br />

integer $seconds Number of seconds<br />

Return Value:<br />

Response<br />

Right, so this method sets the time-to-live value for shared caches. I’m no expert on this kind of<br />

thing, but a time to live suggests how long a piece of information is considered useful before it is<br />

discarded. In this instance the TTL relates to the content caching.<br />

Let’s give it a value for funsies. Having looked at the method signature, we see that it accepts an<br />

integer representing the time-to-live value in seconds. Let’s give this response 60 seconds to live.<br />

Like some kind of cruel James Bond villain.<br />

¹⁹http://api.symfony.com/2.2/Symfony/Component/HttpFoundation/Response.html“TheSymfonyResponseObject”

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!