PHPackages                             phpmicroservice/cache\_manage - 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. phpmicroservice/cache\_manage

ActiveLibrary[Caching](/categories/caching)

phpmicroservice/cache\_manage
=============================

一个缓存管理工具

v1.0.1\_Beta(5y ago)01MITPHPPHP ^7.0

Since Feb 4Pushed 5y ago1 watchersCompare

[ Source](https://github.com/phpmicroservice/cache_manage)[ Packagist](https://packagist.org/packages/phpmicroservice/cache_manage)[ RSS](/packages/phpmicroservice-cache-manage/feed)WikiDiscussions master Synced 5d ago

READMEChangelog (1)Dependencies (5)Versions (3)Used By (0)

cache\_manage 缓存管理器
===================

[](#cache_manage-缓存管理器)

特色
--

[](#特色)

1. 专注与缓存管理（将缓存管理与逻辑分离）
2. 缓存标签
3. 标签关联（自动更新关联标签）

使用案例
----

[](#使用案例)

> 简单版本

```
# 定义缓存驱动
# 详见 src/Driver/Symfony.php

# 定义缓存管理器

/**
 * Description of Time3
 * 三秒缓存
 * @author dongasai
 */
class Time3 extends \CacheManage\AbstractCache
{

    protected $ttl    = 3;
    protected $dirver = Symfony::class;

    public function handle()
    {
        return time();
    }

}

# 使用缓存管理器，这个缓存管理器是无参数的
$time3 = new Time3();
$timeCache = $time3->get();

echo $timeCache;
```

> 带有标签的

```
/**
 * Description of Team
 * 组 缓存管理
 * @method \test\Table\Team get()
 * @author dongasai
 */
class Team extends \CacheManage\AbstractCache
{
    protected $dirver = Symfony::class;

    public function handle()
    {
        $id = $this->param_arr[0];
        $team = new \test\Table\Team(['id'=>$id]);
        $this->selfTags[] = "team_$id";
        return $team;
    }
}

/**
 * 用户 缓存管理
 * @method \test\Table\User get()
 */
class User extends AbstractCache
{

    protected $dirver = Symfony::class;

    public function selfTags(): array
    {
        return $this->selfTags;
    }

    public function handle()
    {
        $id                  = $this->param_arr[0];
        $this->selfTags[]    = "user_$id";
        $user                = new \test\Table\User(['id' => $id]);
        $teamId              = $user->getTeamId();
        $this->relatedTags[] = "team_$teamId";

        return $user;
    }

}
$User = new User();
$UserCache = $User->get([1]);

```

使用说明
----

[](#使用说明)

1. 缓存驱动
    - 继承`\CacheManage\AbstractDriver`
    - 实现所需要实现的方法，其中`getInstance`方法是静态的、公开的
2. 缓存管理类
    - 要继承`\CacheManage\AbstractCache`
    - 要设置`dirver`属性，`protected string $dirver = Symfony::class;`,这是设置改缓存管理器的缓存驱动
    - 默认标签储存的驱动为`Predis`,可修改为其他，示例：`test/Cache/One/AbstractCache.php`，需确保所有的缓存管理器类公用一个标签储存驱动，不公用一个标签储存驱动的话就不能自动更新关联缓存
    - 自我标签。`array $selfTags`属性储存自我标签，就是当前缓存的标签，当别的缓存关联了这个标签是，当前缓存更新则关联更新其他缓存,一个缓存可以有多个自我标签
    - 关联标签。`array $relatedTags`属性储存了关联标签，当这些标签的缓存有更新时，当前缓存会被关联更新
    - 标签可以是任意可序列化(`serialize`)的变量
    - 缓存获取的参数。`array $param_arr`属性储存了缓存获取参数，在实例化缓存管理、获取数据是可传入参数,例： ```
        //实例化传入参数
        (new User([1]))->get();
        // 获取时传入参数，会覆盖原本的参数
         (new User())->get([1]);
        ```
    - 缓存过去时间。`int $ttl`属性储存了缓存的过期时间，是指在多少秒后过期。可直接定义缓存获取可时间`protected $ttl = 60;`，也可在实例化管理管理类、获取数据的时候传入过期时间，例： ```
        // 实例化传入过期时间
        (new User([1],100))->get();
        // 获取数据时传入过期时间，，会覆盖原本的过期时间
        (new User())->get([1],100);
        ```
    - 缓存获取方法,`handle`方法为缓存的获取方法，可在此方法内根据参数获取待缓存数据，数据直接返回即可。例：

    ```
    public function handle()
    {
        $offset = $this->param_arr[0];
        return time() + $offset;
    }
    ```
3. 使用缓存管理器
    - 定义驱动
    - 定义缓存管理类
    - 实例化缓存管理类，获取数据

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity1

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 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

Every ~1 days

Total

2

Last Release

1924d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6934999dc4a6b6b8c08bf4c6d076da9e0b90d55d6d5c86917cf919ab2aced271?d=identicon)[dongasai](/maintainers/dongasai)

---

Top Contributors

[![dongasai](https://avatars.githubusercontent.com/u/16734530?v=4)](https://github.com/dongasai "dongasai (3 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/phpmicroservice-cache-manage/health.svg)

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

###  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)[wp-media/wp-rocket

Performance optimization plugin for WordPress

7431.3M3](/packages/wp-media-wp-rocket)[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)

PHPackages © 2026

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