Source for file Cache.php
Documentation is available at Cache.php
// +----------------------------------------------------------------------+
// | PEAR :: HTTP :: Header :: Cache |
// +----------------------------------------------------------------------+
// | This source file is subject to version 3.0 of the PHP license, |
// | that is available at http://www.php.net/license/3_0.txt |
// | If you did not receive a copy of the PHP license and are unable |
// | to obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Wolfram Kriesing <wk@visionp.de> |
// | Michael Wallner <mike@php.net> |
// +----------------------------------------------------------------------+
// $Id: Cache.php,v 1.19 2004/08/05 15:48:20 mike Exp $
require_once 'HTTP/Header.php';
* 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 done by sending the HTTP-Status "304 Not Modified", so that your
* application load and the network traffic can be reduced, since you only need
* to send the complete page once. This is really an advantage e.g. for
* generated style sheets, or simply pages that do only change rarely.
* require_once 'HTTP/Header/Cache.php';
* $httpCache = new HTTP_Header_Cache(4, 'weeks');
* $httpCache->sendHeaders();
* @version $Revision: 1.19 $
* Set the amount of time to cache.
* @return object HTTP_Header_Cache
$this->setHeader('Cache-Control', 'private, must-revalidate, max-age=0');
* Returns the unix timestamp of the If-Modified-Since HTTP header or the
* current time if the header was not sent by the client.
* @return int unix timestamp
if (isset ($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
$_SERVER['HTTP_IF_MODIFIED_SINCE'])));
* You can call it like this:
* $httpCache->isOlderThan(1, 'day');
* $httpCache->isOlderThan(47, 'days');
* $httpCache->isOlderThan(1, 'week');
* $httpCache->isOlderThan(3, 'weeks');
* $httpCache->isOlderThan(1, 'hour');
* $httpCache->isOlderThan(5, 'hours');
* $httpCache->isOlderThan(1, 'minute');
* $httpCache->isOlderThan(15, 'minutes');
* $httpCache->isOlderThan(1, 'second');
* $httpCache->isOlderThan(15);
* If you specify something greater than "weeks" as time untit, it just
* works approximatly, because a month is taken to consist of 4.3 weeks.
* @return bool Returns true if requested page is older than specified.
* @param int $time The amount of time.
* @param string $unit The unit of the time amount - (year[s], month[s],
* week[s], day[s], hour[s], minute[s], second[s]).
if (!isset ($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
* Check whether we can consider to be cached on the client side.
* @return bool Whether the page/resource is considered to be cached.
* @param int $lastModified Unix timestamp of last modification.
if (isset ($_SERVER['HTTP_IF_MODIFIED_SINCE']) && !$lastModified) {
if (!$seconds = time() - $lastModified) {
* Exit with "HTTP 304 Not Modified" if we consider to be cached.
* @param int $lastModified Unix timestamp of last modification.
* Exit with "HTTP 304 Not Modified".
* @param int $lastModified The unix timestamp of last modification.
$this->setHeader('Last-Modified', $lastModified);
Documentation generated on Mon, 11 Mar 2019 13:54:10 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|