PHPackages                             yiranzai/file-cache - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. yiranzai/file-cache

ActiveLibrary[Caching](/categories/caching)

yiranzai/file-cache
===================

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

v1.0.0(7y ago)331MITPHPPHP ~7.1

Since Mar 14Pushed 7y ago1 watchersCompare

[ Source](https://github.com/yiranzai/php-file-cache)[ Packagist](https://packagist.org/packages/yiranzai/file-cache)[ Docs](https://github.com/yiranzai/php-file-cache)[ RSS](/packages/yiranzai-file-cache/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

file-cache
==========

[](#file-cache)

 [![](https://camo.githubusercontent.com/22d8a983d52692a50bcaa3cd9854a9bcb2ef44b4711343cde823c9bd6804d425/68747470733a2f2f63646e2e796972616e7a61692e636e2f796972616e7a61692f6c6f676f2f6d6f7573652f6d6f757365312e706e67)](https://camo.githubusercontent.com/22d8a983d52692a50bcaa3cd9854a9bcb2ef44b4711343cde823c9bd6804d425/68747470733a2f2f63646e2e796972616e7a61692e636e2f796972616e7a61692f6c6f676f2f6d6f7573652f6d6f757365312e706e67)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ba7b2df7df2f766e1350296b5674979d2d015bf74b4f1f3066e4518bdad7845d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f796972616e7a61692f66696c652d63616368652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/yiranzai/file-cache)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/66d8fc54eca91c94702efdbb0ad28083f9040c4906ba140b3e33119751612973/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f796972616e7a61692f7068702d66696c652d63616368652f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/yiranzai/php-file-cache)[![Coverage Status](https://camo.githubusercontent.com/97c00deaec62028a2d39580512e1f33fa0ca643aaaa270178cb70ddc80c8fbf9/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f796972616e7a61692f7068702d66696c652d63616368652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/yiranzai/php-file-cache/code-structure)[![Quality Score](https://camo.githubusercontent.com/132b3282a0fe055c6c069647bf64b3505e34ab4e71fa26d8be28388b4c40b687/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f796972616e7a61692f7068702d66696c652d63616368652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/yiranzai/php-file-cache)[![Total Downloads](https://camo.githubusercontent.com/4867136dc9f18a61255ef4ddbad5db1b99586c0eccef5a48b97b8a6460ac744b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f796972616e7a61692f66696c652d63616368652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/yiranzai/file-cache)

PHP File Cache, use [Separate Chaining](https://en.wikipedia.org/wiki/Hash_table#separate_chaining) resolve hash conflict. one cache, one file, one bucket.

Feature
-------

[](#feature)

- Cache can set expired time.
- Use [Separate Chaining](https://en.wikipedia.org/wiki/Hash_table#separate_chaining) resolve hash conflict.
- Hash key is the path to store data.

Structure
---------

[](#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
-------

[](#install)

Via Composer

```
$ composer require yiranzai/file-cache
```

Usage
-----

[](#usage)

### API

[](#api)

This package provides these methods.

- `put($key, $data, $minutes): Cache` put one cache to file,set expired time
    - `$minutes` can be a `int` or `DateTime` or `null` or [Supported Date and Time Formats ](http://us1.php.net/manual/zh/datetime.formats.php)
- `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

[](#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
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CODE\_OF\_CONDUCT](CODE_OF_CONDUCT.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [yiranzai](https://github.com/yiranzai)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2617d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/131c451d3fbf74a922387ce2b4c1e0e2e282afcabe8f67a09fc9fa25bbb09799?d=identicon)[yiranzai](/maintainers/yiranzai)

---

Top Contributors

[![yiranzai](https://avatars.githubusercontent.com/u/20548510?v=4)](https://github.com/yiranzai "yiranzai (5 commits)")

---

Tags

file cacheyiranzai

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/yiranzai-file-cache/health.svg)

```
[![Health](https://phpackages.com/badges/yiranzai-file-cache/health.svg)](https://phpackages.com/packages/yiranzai-file-cache)
```

###  Alternatives

[predis/predis

A flexible and feature-complete Redis/Valkey client for PHP.

7.8k305.7M2.4k](/packages/predis-predis)[snc/redis-bundle

A Redis bundle for Symfony

1.0k39.4M67](/packages/snc-redis-bundle)[react/cache

Async, Promise-based cache interface for ReactPHP

444112.4M40](/packages/react-cache)[illuminate/cache

The Illuminate Cache package.

12835.6M1.4k](/packages/illuminate-cache)[colinmollenhour/php-redis-session-abstract

A Redis-based session handler with optimistic locking

6325.6M14](/packages/colinmollenhour-php-redis-session-abstract)[iazaran/smart-cache

Smart Cache is a caching optimization package designed to enhance the way your Laravel application handles data caching. It intelligently manages large data sets by compressing, chunking, or applying other optimization strategies to keep your application performant and efficient.

2057.2k](/packages/iazaran-smart-cache)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
