HTTP_Header
[ class tree: HTTP_Header ] [ index: HTTP_Header ] [ all elements ]

Class: HTTP_Header_Cache

Source Location: /HTTP_Header-0.2.0/Header/Cache.php

Class Overview

HTTP
   |
   --HTTP_Header
      |
      --HTTP_Header_Cache

This package provides methods to easier handle caching of HTTP pages.


Author(s):

Version:

  • $Revision: 1.18 $

Methods


Inherited Variables

Inherited Methods

Class: HTTP_Header

HTTP_Header::HTTP_Header()
Constructor
HTTP_Header::dateToTimestamp()
Date to Timestamp
HTTP_Header::getHeader()
Get Header
HTTP_Header::getHttpVersion()
Get HTTP version
HTTP_Header::getStatusText()
Return Status Code Message
HTTP_Header::getStatusType()
Return HTTP Status Code Type
HTTP_Header::isClientError()
Checks if HTTP Status code is a Client Error (4xx)
HTTP_Header::isError()
Checks if HTTP Status code is Server OR Client Error (4xx or 5xx)
HTTP_Header::isInformational()
Checks if HTTP Status code is Information (1xx)
HTTP_Header::isRedirect()
Checks if HTTP Status code is a Redirect (3xx)
HTTP_Header::isServerError()
Checks if HTTP Status code is Server Error (5xx)
HTTP_Header::isSuccessful()
Checks if HTTP Status code is Successful (2xx)
HTTP_Header::redirect()
Redirect
HTTP_Header::sendHeaders()
Send Headers
HTTP_Header::sendStatusCode()
Send Satus Code
HTTP_Header::setHeader()
Set Header
HTTP_Header::setHttpVersion()
Set HTTP version

Class Details

[line 58]
This package provides methods to easier handle caching of HTTP pages.

That means that the pages can be cached at the client (User agent or browser) and your application only needs to send "hey client you already have the pages". Which is dont by sending the HTTP-Status 304 ('Not Modified'), so that your application load can be reduced and the net traffic too, since you only need to send the complete page once. This is really an advantage i.e. for generated style sheet, or simply pages that do only change rarely.

I.e. when you dont want to send a client-side-cached page multiple times you can do this:

  1.  $httpCache = new HTTP_Header_Cache();
  2.  // if the page is cached, then we send a 304-Not modified header here and EXIT the code right here!
  3.  // if not this method sets all the headers so that the page gets cached
  4.  $httpCache->exitIfCached();
  5.  
  6.  ...do the work that renders the real pagethat shall be cached by the client...

Or when you know that the page shall only be cached for some time:

  1.  $httpCache = new HTTP_Header_Cache();
  2.  // check if the page the client has is older than 2 days
  3.  if ($httpCache->isOlderThan(2,'days')) {
  4.      $httpCache->sendHeaders()// make sure that the headers, that tell this page shall be cached get sent
  5.      ...generate and send all the cacheable content to the client...
  6.  else {
  7.      $httpCache->exitIfCached();
  8.  }



[ Top ]


Method Detail

HTTP_Header_Cache (Constructor)   [line 71]

HTTP_Header_Cache HTTP_Header_Cache( [boolean $caching = true], integer 1)


Parameters:

integer   1   —  the number of seconds after which the page expires
  1. - is never
boolean   $caching   —  shall the

[ Top ]

exitIfCached   [line 169]

void exitIfCached( [boolean $condition = true])

this method exits the script if the page is

still cached by the user agent, the condition if given will be AND-ed to the 'isCached' call Since it returns false in case the page is not cached you can also use it in an if. for example: if (!$httpCache->exitIfCached()) { do stuff here in case it is not cached }


Parameters:

boolean   $condition   —  will be AND-ed to the 'isCached' call

[ Top ]

getCacheStart   [line 80]

void getCacheStart( )


[ Top ]

isCached   [line 139]

void isCached( [boolean $condition = true])

optionally you can pass an additional condition via parameter

which is simply checked for true it would be the same as $this->isCached() && $condition === $this->isCached($condition) it is suggested to use the parameter since the handling for sending the 'last-modified' is included in this method here


Parameters:

boolean   $condition   — 

[ Top ]

isOlderThan   [line 109]

boolean isOlderThan( [integer $time = 0], [string $unit = ''])

You can call it like this:

  1.    $httpCache->isOlderThan(1,'day');
  2.    $httpCache->isOlderThan(47,'days');
  3.  
  4.    $httpCache->isOlderThan(1,'week');
  5.    $httpCache->isOlderThan(3,'weeks');
  6.  
  7.    $httpCache->isOlderThan(1,'hour');
  8.    $httpCache->isOlderThan(5,'hours');
  9.  
  10.    $httpCache->isOlderThan(1,'minute');
  11.    $httpCache->isOlderThan(15,'minutes');
  12.  
  13.    $httpCache->isOlderThan(1,'second');
  14.    $httpCache->isOlderThan(15);    // is the same as isOlderThan(15,'seconds')

  • Return: true if it is older than what the parameters say

Parameters:

integer   $time   —  the number of units, if no second paramter given it means seconds
string   $unit   —  the unit, can be one of: 'week', 'weeks', 'day', 'days', 'hour', 'hours', 'minute', 'minutes', 'second'

[ Top ]


Documentation generated on Mon, 11 Mar 2019 10:17:27 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.