Neos\Flow\Http\Headers::setCacheControlDirective PHP Method

setCacheControlDirective() public method

Sets a special directive for use in the Cache-Control header, according to RFC 2616 / 14.9
public setCacheControlDirective ( string $name, string $value = null ) : void
$name string Name of the directive, for example "max-age"
$value string An optional value
return void
    public function setCacheControlDirective($name, $value = null)
    {
        switch ($name) {
            case 'public':
                $this->cacheDirectives['visibility'] = 'public';
                break;
            case 'private':
            case 'no-cache':
                $this->cacheDirectives['visibility'] = $name . (!empty($value) ? '="' . $value . '"' : '');
                break;
            case 'no-store':
            case 'no-transform':
            case 'must-revalidate':
            case 'proxy-revalidate':
                $this->cacheDirectives[$name] = $name;
                break;
            case 'max-age':
            case 's-maxage':
                $this->cacheDirectives[$name] = $name . '=' . $value;
                break;
        }
    }

Usage Example

 /**
  * @dataProvider cacheDirectivesAndExampleValues
  * @test
  */
 public function getCacheControlDirectiveReturnsTheSpecifiedDirectiveValueIfPresent($name, $value)
 {
     $headers = new Headers();
     $this->assertNull($headers->getCacheControlDirective($name));
     if ($value === true) {
         $headers->setCacheControlDirective($name);
     } else {
         $headers->setCacheControlDirective($name, $value);
     }
     $this->assertEquals($value, $headers->getCacheControlDirective($name));
 }