PHP Class Bluz\Http\CacheControl

Wrapper for working with HTTP headers - Cache-Control - Last-Modified - Expires - ETag - Age
Inheritance: use trait Bluz\Common\Container\Container
Show file Open project: bluzphp/framework Class Usage Examples

Protected Properties

Property Type Description
$response instance

Public Methods

Method Description
__construct ( Response $response ) Create instance
expire ( ) : void Marks the response stale by setting the Age header to be equal to the maximum age of the response
getAge ( ) : integer Returns the age of the response
getEtag ( ) : string Returns the literal value of the ETag HTTP header
getExpires ( ) : string Returns the value of the Expires header as a DateTime instance
getLastModified ( ) : string Returns the Last-Modified HTTP header as a string
getMaxAge ( ) : integer Returns the number of seconds after the time specified in the response's Date header when the response should no longer be considered fresh.
getTtl ( ) : integer | null Returns the response's time-to-live in seconds.
setAge ( integer $age ) : void Set the age of the response
setClientTtl ( integer $seconds ) : void Sets the response's time-to-live for private/client caches.
setEtag ( string $etag, boolean $weak = false ) : void Sets the ETag value
setExpires ( DateTime | string $date ) : void Sets the Expires HTTP header with a DateTime instance
setLastModified ( DateTime | string $date ) : void Sets the Last-Modified HTTP header with a DateTime instance or string
setMaxAge ( integer $value ) : void Sets the number of seconds after which the response should no longer be considered fresh.
setPrivate ( ) : void Marks the response as "private".
setPublic ( ) : void Marks the response as "public".
setSharedMaxAge ( integer $value ) : void Sets the number of seconds after which the response should no longer be considered fresh by shared caches.
setTtl ( integer $seconds ) : void Sets the response's time-to-live for shared caches.

Protected Methods

Method Description
updateCacheControlHeader ( ) : string Prepare Cache-Control header

Method Details

__construct() public method

Create instance
public __construct ( Response $response )
$response Bluz\Response\Response

expire() public method

Marks the response stale by setting the Age header to be equal to the maximum age of the response
public expire ( ) : void
return void

getAge() public method

Returns the age of the response
public getAge ( ) : integer
return integer The age of the response in seconds

getEtag() public method

Returns the literal value of the ETag HTTP header
public getEtag ( ) : string
return string The ETag HTTP header or null if it does not exist

getExpires() public method

Returns the value of the Expires header as a DateTime instance
public getExpires ( ) : string
return string A string or null if the header does not exist

getLastModified() public method

Returns the Last-Modified HTTP header as a string
public getLastModified ( ) : string
return string A string or null if the header does not exist

getMaxAge() public method

First, it checks for a s-maxage directive, then a max-age directive, and then it falls back on an expires header. It returns null when no maximum age can be established.
public getMaxAge ( ) : integer
return integer Number of seconds

getTtl() public method

It returns null when no freshness information is present in the response. When the responses TTL is <= 0, the response may not be served from cache without first revalidating with the origin.
public getTtl ( ) : integer | null
return integer | null The TTL in seconds

setAge() public method

Set the age of the response
public setAge ( integer $age ) : void
$age integer
return void

setClientTtl() public method

This method adjusts the Cache-Control/max-age directive.
public setClientTtl ( integer $seconds ) : void
$seconds integer Number of seconds
return void

setEtag() public method

Sets the ETag value
public setEtag ( string $etag, boolean $weak = false ) : void
$etag string The ETag unique identifier
$weak boolean Whether you want a weak ETag or not
return void

setExpires() public method

Sets the Expires HTTP header with a DateTime instance
public setExpires ( DateTime | string $date ) : void
$date DateTime | string A \DateTime instance or date as string
return void

setLastModified() public method

Sets the Last-Modified HTTP header with a DateTime instance or string
public setLastModified ( DateTime | string $date ) : void
$date DateTime | string A \DateTime instance or date as string
return void

setMaxAge() public method

This methods sets the Cache-Control max-age directive.
public setMaxAge ( integer $value ) : void
$value integer Number of seconds
return void

setPrivate() public method

It makes the response ineligible for serving other clients.
public setPrivate ( ) : void
return void

setPublic() public method

It makes the response eligible for serving other clients.
public setPublic ( ) : void
return void

setSharedMaxAge() public method

This methods sets the Cache-Control s-maxage directive.
public setSharedMaxAge ( integer $value ) : void
$value integer Number of seconds
return void

setTtl() public method

This method adjusts the Cache-Control/s-maxage directive.
public setTtl ( integer $seconds ) : void
$seconds integer Number of seconds
return void

updateCacheControlHeader() protected method

Prepare Cache-Control header
protected updateCacheControlHeader ( ) : string
return string

Property Details

$response protected property

instance
protected $response