PHP File Cache, use Separate Chaining resolve hash conflict. one cache, one file, one bucket.
- Cache can set expired time.
- Use Separate Chaining resolve hash conflict.
- Hash key is the path to store data.
If any of the following are applicable to your project, then the directory structure should follow industry best practices by being named the following.
src/
tests/
vendor/
Via Composer
$ composer require yiranzai/file-cache
This package provides these methods.
put($key, $data, $minutes): Cache
put one cache to file,set expired time$minutes
can be aint
orDateTime
ornull
or Supported Date and Time Formats
forever($key, $data): Cache
forever save one cache to fileget($key, $default = null): ?string
get the data corresponding to the keydelete($key): bool
delete one cacheflush(): void
delete all cachedataPath($path): self
change data save path
$cache = new Yiranzai\File\Cache();
$cache->put('key', 'data', 10);
$cache->put('key1', 'data1', new DateTime());
$cache->put('key2', 'data2', 'now');
$cache->forever('key3', 'data3');
$cache->get('key'); // data
$cache->delete('key'); // true
$cache->flush();
$cache->get('not_exists','nothing'); // nothing
$cache->dataPath('YOUR_PATH');
// or
$cache = new Yiranzai\File\Cache(['dataPath'=>'YOUR_PATH']);
Please see CHANGELOG for more information on what has changed recently.
$ composer test
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
If you discover any security related issues, please email wuqingdzx@gmail.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.