PHP Classes

PHP Cache Page Content: Cache the output of Web pages in files

Recommend this page to a friend!
  Info   View files Example   View files View files (4)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 129 All time: 9,362 This week: 206Up
Version License PHP version Categories
caching-class-php 1.0GNU General Publi...5.0PHP 5, Files and Folders, Cache


This class can cache the output of Web pages in files.

It takes the URL of the current page and checks if there is already a cache file with the page contents.

If the cache file exists and is not expired, the class serves the cache file contents.

Otherwise the class start output buffering capture so the page output can be stored in a cache file.

It is a Url base cache system based on output buffereing for php server and it is very useful for speeding up any websites ,and all of the configuration can be passed to constructor for overriding the default value like cache time ,cache folder name.

Picture of Jeetendra Singh
Name: Jeetendra Singh <contact>
Classes: 1 package by
Country: India India
Age: ???
All time rank: 4333297 in India India
Week rank: 280 Up21 in India India Up


include 'cache.class.php';

//parameters list//
$cache_ext = '.html';//cache file extension
$cache_time = 3600; //in seconds eg: 3600=60*60 means 1 hour cache time
$cache_folder = 'cache_gen/'; //folder in which you want to save cache
$ignore_urls = array();//define a array with full url which you want to ignore for generating cache.
$cache_enable=1; //0 for disable caching and 1 for enable caching functionality.
//parameters list//
$cache_obj=new cache($cache_ext,$cache_time,$cache_folder,$ignore_urls,$cache_enable);

<!DOCTYPE html>
        <title>Page to Cache</title>
           <p> para1<p>
           <p> para2 test<p>
           <p> my anything dynamic data from any data source<p>

if (!is_dir($cache_obj->cache_folder)) { //create a new folder if we need to
$fp = fopen($cache_obj->_cache_file, 'w'); //open file for writing
fwrite($fp, ob_get_contents()); //write contents of the output buffer in Cache file
fclose($fp); //Close file pointer
ob_end_flush(); //Flush and turn off output buffering




created a custom class for achieve cache system using php

  Files folder image Files  
File Role Description
Plain text file cache.class.php Class Class source
Accessible without login Plain text file example.php Example Example script
Accessible without login Plain text file LICENSE Data Auxiliary data
Accessible without login Plain text file Data Auxiliary data

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:9,362
This week:206Up