Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/piotrpress/cacher
This library provides a simple file-based caching solution.
https://github.com/piotrpress/cacher
Last synced: 5 days ago
JSON representation
This library provides a simple file-based caching solution.
- Host: GitHub
- URL: https://github.com/piotrpress/cacher
- Owner: PiotrPress
- License: mit
- Created: 2023-10-29T22:50:04.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2024-09-16T09:19:46.000Z (about 2 months ago)
- Last Synced: 2024-10-27T21:15:49.586Z (18 days ago)
- Language: PHP
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.txt
Awesome Lists containing this project
README
# Cacher
This library provides a simple file-based caching solution.
## Installation
```shell
$ composer require piotrpress/cacher
```## Usage
```php
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](license.txt)