PHPackages                             hejunjie/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. hejunjie/cache

ActiveLibrary[Caching](/categories/caching)

hejunjie/cache
==============

基于装饰器模式实现的多层缓存系统，支持内存、文件、本地与远程缓存组合，提升缓存命中率，简化缓存管理逻辑 | A layered caching system built with the decorator pattern. Supports combining memory, file, local, and remote caches to improve hit rates and simplify cache logic.

v1.0.3(11mo ago)1512↓37.5%1MITPHPPHP &gt;=8.1

Since Apr 12Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/zxc7563598/php-cache)[ Packagist](https://packagist.org/packages/hejunjie/cache)[ RSS](/packages/hejunjie-cache/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)DependenciesVersions (5)Used By (1)

hejunjie/cache
==============

[](#hejunjiecache)

 [English](./README.md)｜[简体中文](./README.zh-CN.md)---

A layered caching system built with the decorator pattern. Supports combining memory, file, local, and remote caches to improve hit rates and simplify cache logic.

**This project has been parsed by Zread. If you need a quick overview of the project, you can click here to view it：[Understand this project](https://zread.ai/zxc7563598/php-cache)**

---

This is a multi-layer caching system I built myself, mainly to flexibly combine different cache layers (like memory, Redis, and file) in my projects.

The project requirements were quite diverse, and the caching tools provided by frameworks were either too limited or lacked transparency. So, I decided to build my own solution—something tailored to my own needs. If you happen to have similar requirements, I hope this package proves useful to you 🙌.

Features
--------

[](#features)

- Supports multi-layer cache combinations with a nested cache structure, becoming more stable as it goes deeper.
- Based on the decorator pattern, extending new types of caches is very easy.
- Memory cache supports hit rate statistics, making it easier to observe and optimize.
- File cache supports concurrent locks, making it suitable for data caching in CLI scenarios.
- Custom data source interface—just implement `Interfaces\DataSourceInterface` to integrate any data source.

Installation
------------

[](#installation)

Install via Composer:

```
composer require hejunjie/cache
```

Quick Start
-----------

[](#quick-start)

**Note**: For ease of extension, the code only implements the cache layer (memory/redis/file). In actual use cases, it is recommended to complete the data layer yourself. The example code is shown below.

```
