Download the PHP package tschueller/simplephpcache without Composer
On this page you can find all versions of the php package tschueller/simplephpcache. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tschueller/simplephpcache
More information about tschueller/simplephpcache
Files in tschueller/simplephpcache
Package simplephpcache
Short Description A very simple PHP caching system which can cache HTML output or variables.
License MIT
Informations about the package simplephpcache
SimplePhpCache
A very simple PHP caching system which can cache HTML output or variables.
Requirements
- PHP 8.2 or higher
Preparation
Install the package with Composer:
composer require tschueller/simplephpcache
Load Composer's autoloader and import the class:
// Output your html stuff here
<h1>Test</h1>
<?=generateOutput();?>
Cache a variable
Clear the cache
Clear all cache files
SimplePhpCache::clearCache();
Optionally register a callback once during application startup. It receives the
cleared cache ID, cleared prefix, and number of deleted files. ID and prefix
are both null when the complete cache is cleared:
SimplePhpCache::setAfterCacheClearedCallback(
static function (?string $id, ?string $idPrefix, int $clearedFileCount): void {
// Clear a related application cache or write an audit log.
}
);
Pass null to setAfterCacheClearedCallback() to remove the callback. The
callback is invoked only after all matching cache files were deleted. If it
throws an exception, the cache has already been cleared and the exception is
passed to the caller. If a matching cache file cannot be deleted,
clearCache() throws a RuntimeException and does not invoke the callback.
To refresh a special cache file, set in the init method as the second parameter true
// HTML
SimplePhpCache::initHTMLCaching($cacheName, true)
// Variable
SimplePhpCache::initVarCaching($cacheName, true)
To override the cache lifetime for a single cache entry without changing the
global SimplePhpCache::$maxCacheTime, pass its lifetime in seconds as the
third parameter:
// Cache this entry for 5 minutes
SimplePhpCache::initHTMLCaching($cacheName, false, 300)
SimplePhpCache::initVarCaching($cacheName, false, 300)
Migration
See docs/migration.md for all migration paths, including
the separately maintained PhaseUtils fork.
Release Process
For the release process, versioning rules, changelog requirements, and GitHub Actions automation, see docs/releasing.md.