PHP Classes

PHP Fast Cache Class: Cache a script output to avoid running it again

Recommend this page to a friend!
  Info   Documentation   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: 84 All time: 10,045 This week: 488Up
Version License PHP version Categories
fast-cache 1.0.0Custom (specified...7PHP 5, Files and Folders, Cache
Description 

Author

This package can cache a script output to avoid running it again.

It can check if a given cache file exists in a given cache directory.

If the file does not exist or it was created after a time more than the cache expiry time, the class starts capturing the output of the current script. Otherwise, it outputs the previous cached content.

If the cached content was not yet previously stored in the cache file or it was stored but it already expired, the class stores the current script output in the cache file after the script ends.

Picture of Lluís Camino
  Performance   Level  
Name: Lluís Camino <contact>
Classes: 2 packages by
Country: Spain Spain
Age: ???
All time rank: 3809102 in Spain Spain
Week rank: 178 Up6 in Spain Spain Up
Innovation award
Innovation award
Nominee: 1x

Documentation

fast-cache

Simple caching system for PHP applications.

Installing

Use the following command to install via Composer:

composer require lluiscamino/fast-cache

Usage

$cache = new FastCache(21600); // Cache lifetime in seconds
$cache->start();
echo "Hola!"; // Display content
$cache->end();

Once a user visits your website for the first time, a cached version of the page will be created and served for the following requests in the specified time.

If for some reason you don't want the current content to be saved, you can finish with $cache->end(false); and the content will not be cached.

Apart from time, you can also specify two more parameters in the constructor:

__construct(int $time, string $file = null, string $dir = '')
  • `string $file`: Name of the (file.php) that identifies the page being cached. Use this option to create different cached versions of the same page. Leave blank to automatically select the file from which the object is being created.
  • `string $dir`: Subdirectory where the cache file of the page will be saved.

Configuration

FastCache::$path = 'custom-dir'; // Cache files directory
FastCache::$announce = false; // Disable "Serving cached file fromServing cached file from..." comment

  Files folder image Files (5)  
File Role Description
Files folder imagedocs (1 file)
Files folder imagesrc (1 directory)
Plain text file composer.json Data Auxiliary data
Plain text file LICENSE Lic. License text
Plain text file README.md Doc. Documentation

  Files folder image Files (5)  /  docs  
File Role Description
  Plain text file FastCache.pdf Data Auxiliary data

  Files folder image Files (5)  /  src  
File Role Description
Files folder imagelluiscamino (1 file)

  Files folder image Files (5)  /  src  /  lluiscamino  
File Role Description
  Plain text file FastCache.php Class Class source

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  
 100%
Total:84
This week:0
All time:10,045
This week:488Up