HTTP Cache
The HTTP Cache is a client-side cache that prevents unnecessary data transfers and has a very positive effect on performance.
HTTP Cache Control
Via ControllerAdapter::assignHttpCacheControl() you can modify the HTTP caching headers (e.g. "Cache-Control", "Pragma", etc.) in a simple way. Via a \DateInterval you define how long the response should be cached in the browser.
class ExampleController extends ControllerAdapter {
public function doFoo() {
$this->assignHttpCacheControl(new \DateInterval('PT30M'));
$this->forward('view\bar.html');
}
}
If you want to define directives for the HTTP header "Cache-Control" yourself, you can do so via the second parameter:
$this->assignHttpCacheControl(new \DateInterval('PT30M'),
array(HttpCacheControl::DIRECTIVE_PUBLIC,
HttpCacheControl::DIRECTIVE_PROXY_REVALIDATE));
Applying
Since the HTTP Cache is a client-side cache, there is no way to clear the cache from within the application, as is possible for example with the Response Cache via the Response Cache Store. But that should not stop you from using the HTTP Cache for as many of your pages as possible. Even very short cache times can greatly reduce server requests and improve the user experience.