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

ActiveLibrary[Caching](/categories/caching)

codeages/cache-sync
===================

Cache Sync

v1.0.4(8y ago)13.3kMITPHP

Since May 15Pushed 8y ago2 watchersCompare

[ Source](https://github.com/codeages/cache-sync)[ Packagist](https://packagist.org/packages/codeages/cache-sync)[ RSS](/packages/codeages-cache-sync/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (3)Versions (8)Used By (0)

Cache Sync
==========

[](#cache-sync)

[![Build Status](https://camo.githubusercontent.com/08352e89c590b35aa35071538ec743be1a20b4919d45c6a5e574d7f6404b107e/68747470733a2f2f7472617669732d63692e6f72672f636f6465616765732f63616368652d73796e632e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/codeages/cache-sync)

应用为了解决单数据中心的单点问题，往往会在多数据中心部署。主数据中心的 MySQL 通常会通过 MySQL 复制的方式同步到从数据中心，而通常从数据中心也有 Cache 层，这时 Cache 层无法感知数据库层数据有更新，导致读到旧数据。因此当主数据中心的 MySQL 数据有更新时，需要通知从数据中心清除 Cache，这个项目就是为了这个需求而生。

实现原理
----

[](#实现原理)

主数据中心更新数据时，同时将需要更新的 Cache Key 记录到 MySQL 的表中，然后通过 MySQL 复制同步到从数据中心。从数据中心启动一个后台服务，查询有更新的 Cache Key 记录，清除Cache Key 或重置 Cache Key 的值。

**注意：该方案适用于数据更新不怎么频繁的场景，数据更新频繁可以采用解析 MySQL Binlog 做同步更新 Cache 的方案。**

Usage
-----

[](#usage)

**创建Cache同步记录表**

```
CREATE TABLE `cache_sync` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `op` enum('set','del') NOT NULL COMMENT 'Cache操作',
  `k` varchar(1024) NOT NULL DEFAULT '' COMMENT 'Cache的Key',
  `v` text COMMENT '当op为set时，v为set的值',
  `t` int(10) unsigned NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=663 DEFAULT CHARSET=utf8;
```

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity68

Established project with proven stability

 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 ~18 days

Recently: every ~5 days

Total

7

Last Release

3271d ago

Major Versions

0.1.1 → 1.0.02017-08-09

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/73380446?v=4)[Wellming](/maintainers/Wellming)[@wellming](https://github.com/wellming)

---

Top Contributors

[![lileiseven](https://avatars.githubusercontent.com/u/94609?v=4)](https://github.com/lileiseven "lileiseven (28 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/codeages-cache-sync/health.svg)

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

###  Alternatives

[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.

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

PHPackages © 2026

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