lluiscamino/fast-cache

Simple caching system for PHP applications

1.0.0 2020-02-12 21:18 UTC

This package is auto-updated.

Last update: 2024-04-13 06:41:03 UTC


README

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