yiranzai / file-cache
PHP File Cache, use Separate Chaining resolve hash conflict. one cache, one file, one bucket.
Requires
- php: ~7.1
- ext-fileinfo: *
- ext-json: *
Requires (Dev)
- phpunit/phpunit: >=7.0
- squizlabs/php_codesniffer: ^3.0
This package is auto-updated.
Last update: 2024-11-14 22:28:36 UTC
README
PHP File Cache, use Separate Chaining resolve hash conflict. one cache, one file, one bucket.
Feature
- Cache can set expired time.
- Use Separate Chaining resolve hash conflict.
- Hash key is the path to store data.
Structure
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/
Install
Via Composer
$ composer require yiranzai/file-cache
Usage
API
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
Demo
$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']);
Change log
Please see CHANGELOG for more information on what has changed recently.
Testing
$ composer test
Contributing
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
Security
If you discover any security related issues, please email wuqingdzx@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.