PHP Classes

PHP Simple Cache: Retrieve the current page from a cache file

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 75 All time: 10,189 This week: 488Up
Version License PHP version Categories
php-simple-cache 0.1BSD License4Files and Folders, Cache
Description 

Author

This class can store and retrieve the current page from a cache file.

It can compute an hash from the current page request URL to determine the name of a cache file on which the current page content will be stored.

The class returns the the cache file contents if it already exists and if it was not created more than a given cache expiry timeout period.

Otherwise the class can create a new cache file using the same file name based on the current request URL.

The cache file directory path is based on the first letter of the cache file name and the base cache file path. If the cache directory does not exist, the class creates it.

The cache file base directory path and the expiry time are configurable parameters.

Picture of Dmitry Stroganov
  Performance   Level  
Name: Dmitry Stroganov <contact>
Classes: 2 packages by
Country: Russian Federation Russian Federation
Age: 45
All time rank: 3651103 in Russian Federation Russian Federation
Week rank: 197 Up9 in Russian Federation Russian Federation Up

Example

<?php

require_once ('cache/cache.php');

class
main {

    function
main() {
   
        ...
       
       
$this->cache = new cache();
   
    }

    ...
   
    function
show() {
   
       
$html = $this->cache->return_cache();
           
        if (
$html == false) {
           
$html = this->render_site();
        }
       
       
$this->cache->make_cache($html);
   
        echo
$html;
    }

}

?>


Details

If your site has mostly static content and you do not want to setup nginx or do not have enough permissions (for example virtual hosting) you may find this class useful for you. Especially if your site more than 5 000 unique visitors per day, your hosting type is virtual hosting, your hosting provider start saying that you better upgrade to VPS/VDS and you do not want to pay more. Steps to use: create a folder named cache in the httpdocs folder of your site, copy cache.php into it, configure path and timeout in the constructor of the class and take a look at the example file attached to this class.

  Files folder image Files (3)  
File Role Description
Files folder imagecache (1 file)
Accessible without login Plain text file index.php Example Sample usage
Accessible without login Plain text file readme.txt Doc. Readme file

  Files folder image Files (3)  /  cache  
File Role Description
  Plain text file cache.php Class Main class

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:75
This week:0
All time:10,189
This week:488Up