{"id":35191042,"url":"https://github.com/codeages/cache-sync","last_synced_at":"2026-05-21T19:32:27.344Z","repository":{"id":56954829,"uuid":"91330463","full_name":"codeages/cache-sync","owner":"codeages","description":null,"archived":false,"fork":false,"pushed_at":"2017-08-31T04:24:26.000Z","size":40,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-12-31T22:30:48.573Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codeages.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-15T11:32:47.000Z","updated_at":"2023-05-22T13:30:05.000Z","dependencies_parsed_at":"2022-08-21T04:10:16.753Z","dependency_job_id":null,"html_url":"https://github.com/codeages/cache-sync","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/codeages/cache-sync","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeages%2Fcache-sync","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeages%2Fcache-sync/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeages%2Fcache-sync/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeages%2Fcache-sync/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codeages","download_url":"https://codeload.github.com/codeages/cache-sync/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeages%2Fcache-sync/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33311811,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-21T12:23:38.849Z","status":"ssl_error","status_checked_at":"2026-05-21T12:22:11.673Z","response_time":62,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-12-29T05:40:03.445Z","updated_at":"2026-05-21T19:32:27.337Z","avatar_url":"https://github.com/codeages.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Cache Sync\n==========\n\n[![Build Status](https://travis-ci.org/codeages/cache-sync.svg?branch=master)](https://travis-ci.org/codeages/cache-sync)\n\n应用为了解决单数据中心的单点问题，往往会在多数据中心部署。主数据中心的 MySQL 通常会通过 MySQL 复制的方式同步到从数据中心，而通常从数据中心也有 Cache 层，这时 Cache 层无法感知数据库层数据有更新，导致读到旧数据。因此当主数据中心的 MySQL 数据有更新时，需要通知从数据中心清除 Cache，这个项目就是为了这个需求而生。\n\n## 实现原理\n\n主数据中心更新数据时，同时将需要更新的 Cache Key 记录到 MySQL 的表中，然后通过 MySQL 复制同步到从数据中心。从数据中心启动一个后台服务，查询有更新的 Cache Key 记录，清除Cache Key 或重置 Cache Key 的值。\n\n**注意：该方案适用于数据更新不怎么频繁的场景，数据更新频繁可以采用解析 MySQL Binlog 做同步更新 Cache 的方案。**\n\n## Usage\n\n**创建Cache同步记录表**\n\n```sql\nCREATE TABLE `cache_sync` (\n  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,\n  `op` enum('set','del') NOT NULL COMMENT 'Cache操作',\n  `k` varchar(1024) NOT NULL DEFAULT '' COMMENT 'Cache的Key',\n  `v` text COMMENT '当op为set时，v为set的值',\n  `t` int(10) unsigned NOT NULL,\n  PRIMARY KEY (`id`)\n) ENGINE=InnoDB AUTO_INCREMENT=663 DEFAULT CHARSET=utf8;\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeages%2Fcache-sync","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodeages%2Fcache-sync","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeages%2Fcache-sync/lists"}