piedweb/file-cache

Permit to manage data in a file. Simple, Static and Intuitive.

0.0.5 2019-01-07 10:10 UTC

This package is auto-updated.

Last update: 2024-11-16 20:57:36 UTC


README

Latest Version Software License Build Status Quality Score Code Coverage Total Downloads

Simple file cache library. Tested and approved. Intuitive and documented (inline and in this Readme).

Install

Via Packagist

$ composer require piedweb/file-cache

Usage

use PiedWeb\FileCache\FileCache;

$key = 'data-2032'; // string to identify the cached data
$maxAge = 3600;     // 1 hour
$folder = './cache';
$prefix = 'tmp_';
$data = 'example data, but can be an int or an array which will be serialized'

/** Create a cache file **/
FileCache::instance()->setPrefix($folder) // Useful when you want to delete every cached data of the same type
FileCache::instance()->setCacheFolder($pregix)


FileCache::instance($folder, $prefix)->set($key, 'My string to set in a cache || But it could be an array or an object...');
FileCache::instance($folder, $prefix)->get($key, $maxAge);
FileCache::instance($folder, $prefix)->get($key, 0);  // Always valid. No expiration
FileCache::instance($folder, $prefix)->getElseCreate($key , $maxAge, function() { return ['My first data in cache']; });

/** Delete all cache files with the prefix `prfixForCacheFiles_` **/
FileCache::instance($folder, $prefix)->deleteCacheFilesByPrefix();

Testing

$ composer test

Contributing

Please see contributing

Credits

License

The MIT License (MIT). Please see License File for more information.

Latest Version Software License Build Status Quality Score Code Coverage Total Downloads