Search by

ez-php / view-cache

AU9500

Output-caching decorator for ez-php/view's ViewEngine, with mtime-based invalidation

Package info

github.com/ez-php/view-cache

pkg:composer/ez-php/view-cache

Statistics

Installs: 7

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

2.4.0 2026-09-14 23:33 UTC

This package is auto-updated.

Last update: 2026-09-14 23:38:40 UTC


README

Output-caching decorator for ez-php/view's ViewEngine. Caches a rendered template's output to a file, keyed by template name and render data, and invalidates it based on the source template file's mtime.

Installation

composer require ez-php/view-cache

Usage

use EzPhp\View\ViewEngine;
use EzPhp\ViewCache\CachingViewEngine;

$viewPath = __DIR__ . '/resources/views';
$engine = new CachingViewEngine(
    new ViewEngine($viewPath),
    $viewPath,
    __DIR__ . '/storage/view-cache',
);

echo $engine->render('home', ['title' => 'Welcome']);

render() mirrors ViewEngine::render()'s signature, so CachingViewEngine is a drop-in substitute anywhere a plain ViewEngine is used directly. A cached entry is served back as long as the source template file's mtime hasn't changed since it was written; editing the template invalidates it automatically.

Wiring this into an application's dependency container (e.g. binding CachingViewEngine instead of ViewEngine behind an environment flag) is left to the application — this module has no framework dependency beyond ez-php/view itself.

License

MIT