piotrpress/cacher

This library provides a simple file-based caching solution.

v1.2.0 2024-09-16 09:19 UTC

This package is auto-updated.

Last update: 2024-11-16 09:43:14 UTC


README

This library provides a simple file-based caching solution.

Installation

$ composer require piotrpress/cacher

Usage

require __DIR__ . '/vendor/autoload.php';

use PiotrPress\Cacher;

$cache = new Cacher( '.cache', 3600 );

$value = $cache->get( 'hi', function ( $arg1, $arg2 ) {
    return "$arg1 $arg2";
}, 'Hello', 'world!' );

$cache->clear( 'hi' ); // clear cache for "hi" key
$cache->clear(); // clear all cache

You can use php://memory as a file to store cache in memory, for instance, while developing or testing.

Cacher takes an expiration time in seconds as the second argument. By default, it is set to -1, which means the cache never expires. If the value 0 is provided, the cache will be cleared on every call.

Requirements

Supports PHP >= 7.4 version.

License

MIT