Bluz\Http\CacheControl::getMaxAge PHP Method

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
    public function getMaxAge()
    {
        if ($this->doContainsContainer('s-maxage')) {
            return (int) $this->doGetContainer('s-maxage');
        }
        if ($this->doContainsContainer('max-age')) {
            return (int) $this->doGetContainer('max-age');
        }
        if ($expires = $this->getExpires()) {
            $expires = \DateTime::createFromFormat(DATE_RFC2822, $expires);
            return $expires->format('U') - date('U');
        }
        return null;
    }

Usage Example

Example #1
0
 /**
  * Test Client Ttl
  */
 public function testClientTtl()
 {
     $this->cacheControl->setClientTtl(3600);
     $this->assertEquals(3600, $this->cacheControl->getTtl());
     $this->assertEquals(3600, $this->cacheControl->getMaxAge());
     $this->assertEquals('max-age=3600', $this->response->getHeader('Cache-Control'));
 }