2017 © Pedro Peláez
 

library cacher

Simple file caching for PHP with string replacements

image

xes/cacher

Simple file caching for PHP with string replacements

  • Saturday, March 21, 2015
  • by xes
  • Repository
  • 1 Watchers
  • 0 Stars
  • 72 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Overview

Cacher provides a simple caching functionality, usable with two lines of code., (*1)

Installation

Add "xes/cacher": "dev-master" to your composer.json file., (*2)

Usage

Before any HTML is output:, (*3)

<?php
$cache = new xes\Cacher('/path/to/cache/folder');
$cache->start();
?>

The path must already exist and be writable by the web server., (*4)

At the end of your script:, (*5)

<?php
$cache->finish();
?>

String replacements

For content such as page title and meta descriptions, you may not know the values until later in the script. For this there is a replacement method in Cacher:, (*6)

<title></title>

setReplacements( array(
    "" => $pageTitleFromDatabase,
    "" => $somethingElse
));
?>

This simply performs a find-and-replace on the HTML until the search text doesn't exist., (*7)

The replacements array can also be passed directly to finish()., (*8)

Settings

setEnabled(true/false) - choose if the cache should run or not. Useful for development environments., (*9)

setFolder(path) - absolute path to the cache folder. Must be writable by web server., (*10)

setTimeout(numberOfSeconds) - how many seconds should elapse until a cached file should be considered invalid., (*11)

setSuffix(fileSuffix) - the file suffix appended to all cache files. .cache.html by default., (*12)

setReplacements(array) - associative array of replacements in the format "find" -> "replace", (*13)

The Versions

21/03 2015

dev-master

9999999-dev https://github.com/dan1elhughes/cacher

Simple file caching for PHP with string replacements

  Sources   Download