PHP Classes

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

Recommend this page to a friend!
  Info   View files Documentation   View files View files (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 84 This week: 1All time: 10,018 This week: 571Up
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: 3804102 in Spain Spain
Week rank: 420 Up10 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  
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  /  docs  
File Role Description
  Plain text file FastCache.pdf Data Auxiliary data

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

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

 Version Control Unique User Downloads Download Rankings  
 100%
Total:84
This week:1
All time:10,018
This week:571Up