https://github.com/piedweb/filecache
[PHP] Permit to manage data in a file. Simple, Static and Intuitive.
https://github.com/piedweb/filecache
Last synced: about 2 months ago
JSON representation
[PHP] Permit to manage data in a file. Simple, Static and Intuitive.
- Host: GitHub
- URL: https://github.com/piedweb/filecache
- Owner: PiedWeb
- License: mit
- Created: 2019-01-06T17:15:49.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-01-16T07:13:40.000Z (over 7 years ago)
- Last Synced: 2025-01-07T11:12:14.592Z (over 1 year ago)
- Language: PHP
- Homepage: https://dev.piedweb.com/
- Size: 8.79 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# File Cache
[](https://github.com/PiedWeb/FileCache/tags)
[](https://github.com/PiedWeb/FileCache/blob/master/LICENSE)
[](https://travis-ci.org/PiedWeb/FileCache)
[](https://scrutinizer-ci.com/g/PiedWeb/FileCache)
[](https://scrutinizer-ci.com/g/PiedWeb/FileCache/code-structure)
[](https://packagist.org/packages/piedweb/file-cache)
Simple file cache library. Tested and approved. Intuitive and documented (inline and in this Readme).
## Install
Via [Packagist](https://img.shields.io/packagist/dt/piedweb/file-cache.svg?style=flat)
``` bash
$ composer require piedweb/file-cache
```
## Usage
``` php
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
``` bash
$ composer test
```
## Contributing
Please see [contributing](https://dev.piedweb.com/contributing)
## Credits
- [PiedWeb](https://piedweb.com)
- [All Contributors](https://github.com/PiedWeb/:package_skake/graphs/contributors)
## License
The MIT License (MIT). Please see [License File](LICENSE) for more information.
[](https://github.com/PiedWeb/FileCache/tags)
[](https://github.com/PiedWeb/FileCache/blob/master/LICENSE)
[](https://travis-ci.org/PiedWeb/FileCache)
[](https://scrutinizer-ci.com/g/PiedWeb/FileCache)
[](https://scrutinizer-ci.com/g/PiedWeb/FileCache/code-structure)
[](https://packagist.org/packages/piedweb/file-cache)