class AuthcacheP13nAddCacheControlHeaderFilter in Authenticated User Page Caching (Authcache) 7.2
Request filter for adding HTTP cache-control headers.
This class provides a filter for adding appropriate HTTP Cache-Control headers to a response.
Hierarchy
- class \AuthcacheP13nAddCacheControlHeaderFilter implements AuthcacheP13nFilterInterface
Expanded class hierarchy of AuthcacheP13nAddCacheControlHeaderFilter
2 string references to 'AuthcacheP13nAddCacheControlHeaderFilter'
- AuthcacheP13nTestRequestBuilder::testRequestResourcesNullFragments in modules/
authcache_p13n/ tests/ authcache_p13n.request-builder.test - Cover authcache_p13n_request_resources().
- authcache_p13n_authcache_p13n_base_request in modules/
authcache_p13n/ authcache_p13n.module - Implements hook_authcache_p13n_base_request().
File
- modules/
authcache_p13n/ includes/ AuthcacheP13nAddCacheControlHeaderFilter.inc, line 14 - Defines request filter for adding HTTP cache-control headers.
View source
class AuthcacheP13nAddCacheControlHeaderFilter implements AuthcacheP13nFilterInterface {
/**
* @var AuthcacheP13nCoreService
*/
protected $coreService;
/**
* Number of seconds the response should be cached in the users browser.
*/
protected $cacheMaxage;
/**
* @var AuthcacheP13nCacheGranularity
*/
protected $cacheGranularity;
/**
* Construct a new instance.
*/
public function __construct(AuthcacheP13nCoreServiceInterface $core_service, $cache_maxage, AuthcacheP13nCacheGranularity $cache_granularity) {
$this->coreService = $core_service;
$this->cacheMaxage = $cache_maxage;
$this->cacheGranularity = $cache_granularity;
}
/**
* {@inheritdoc}
*
* Add Cache-Control header.
*/
public function filter($event, $input) {
if ($this->cacheMaxage) {
if ($this->cacheGranularity
->is(AuthcacheP13nCacheGranularity::PER_USER)) {
$this->coreService
->drupalAddHttpHeader('Cache-Control', 'private, max-age=' . $this->cacheMaxage);
}
else {
$this->coreService
->drupalAddHttpHeader('Cache-Control', 'public, max-age=' . $this->cacheMaxage);
}
}
else {
$this->coreService
->drupalAddHttpHeader('Cache-Control', 'no-cache, must-revalidate, post-check=0, pre-check=0');
}
return $input;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AuthcacheP13nAddCacheControlHeaderFilter:: |
protected | property | ||
AuthcacheP13nAddCacheControlHeaderFilter:: |
protected | property | Number of seconds the response should be cached in the users browser. | |
AuthcacheP13nAddCacheControlHeaderFilter:: |
protected | property | ||
AuthcacheP13nAddCacheControlHeaderFilter:: |
public | function |
Add Cache-Control header. Overrides AuthcacheP13nFilterInterface:: |
|
AuthcacheP13nAddCacheControlHeaderFilter:: |
public | function | Construct a new instance. |