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 2mo 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 72% 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

3179d ago

Major Versions

0.1.1 → 1.0.02017-08-09

### Community

Maintainers

![](https://www.gravatar.com/avatar/8e6f8246b2e0cf9bb1e36263675cd2f86128fde2b44b7db515af38d98d75fb65?d=identicon)[Wellming](/maintainers/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

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