yiranzai/file-cache

PHP File Cache, use Separate Chaining resolve hash conflict. one cache, one file, one bucket.

v1.0.0 2019-03-14 09:35 UTC

This package is auto-updated.

Last update: 2024-11-14 22:28:36 UTC


README

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

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
  • forever($key, $data): Cache forever save one cache to file
  • get($key, $default = null): ?string get the data corresponding to the key
  • delete($key): bool delete one cache
  • flush(): void delete all cache
  • dataPath($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.