设置过期时间(Setting an Expiration Time)¶
The expiration date is one of the easiest and most effective ways to cache a page in the client (browser).
Starting from the current date we add the amount of time the page will be stored
in the browser cache. Until this date expires no new content will be requested from the server:
$expireDate = new DateTime();
$expireDate->modify('+2 months');
$response->setExpires($expireDate);
The Response component automatically shows the date in GMT timezone as expected in an Expires header.
If we set this value to a date in the past the browser will always refresh the requested page:
$expireDate = new DateTime();
$expireDate->modify('-10 minutes');
$response->setExpires($expireDate);
Browsers rely on the client’s clock to assess if this date has passed or not. The client clock can be modified to
make pages expire and this may represent a limitation for this cache mechanism.