HttpCaching: HTTP caching in PHP 5 made easier

Current version: 0.5 (2006-10-08)

HttpCaching is a very simple PHP class to make specifying HTTP caching headers (Cache-Control, Expires, ETag and Last-Modified) easier, and only processing the request if it is needed (otherwise, return a 304 Not Modified).

A simple example is available to show how to use it.

Difference of HTTP headers sent with or without HttpCaching for a PHP script
No caching information With freshFor("1 hour") from HttpCaching
HTTP/1.1 200 OK
Date: Sat, 26 Aug 2006 11:00:07 GMT
Server: Apache/1.3.33 (Unix)
X-Powered-By: PHP/5.1.2
Content-Type: text/html
HTTP/1.1 200 OK
Date: Sat, 26 Aug 2006 11:00:07 GMT
Server: Apache/1.3.33 (Unix)
X-Powered-By: PHP/5.1.2
Expires: Sat, 26 Aug 2006 12:00:07 GMT
Cache-Control: max-age=3600
Last-Modified: Sat, 26 Aug 2006 11:00:07 GMT
Content-Type: text/html

Download

It's composed of one small PHP file: HttpCaching.

Documentation

Documentation of the HttpCaching class is available.

Demo

For more information about HTTP caching

I encourage you to read Mark Nottingham's caching tutorial.


Hugo Haas
$Date: 2006-07-17 05:25:17 -0700 (Mon, 17 Jul 2006) $