piedweb / file-cache
Permit to manage data in a file. Simple, Static and Intuitive.
Installs: 6 141
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ~7.1
Requires (Dev)
- phpunit/phpunit: >=7.0
- squizlabs/php_codesniffer: ^3.0
README
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.