{"id":19765645,"url":"https://github.com/cold-bin/cb-cache","last_synced_at":"2026-02-05T04:02:02.435Z","repository":{"id":195995795,"uuid":"693668773","full_name":"cold-bin/cb-cache","owner":"cold-bin","description":"简易的分布式kv内存数据库","archived":false,"fork":false,"pushed_at":"2024-03-26T09:06:36.000Z","size":141,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-04T22:42:21.746Z","etag":null,"topics":["consistent-hashing","go","kv-store","lru-k-cache"],"latest_commit_sha":null,"homepage":"","language":"Go","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/cold-bin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-09-19T13:31:13.000Z","updated_at":"2024-06-30T04:37:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"583019c4-2974-4d5b-ab27-36c4095b2d55","html_url":"https://github.com/cold-bin/cb-cache","commit_stats":null,"previous_names":["cold-bin/cb-cache"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/cold-bin/cb-cache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cold-bin%2Fcb-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cold-bin%2Fcb-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cold-bin%2Fcb-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cold-bin%2Fcb-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cold-bin","download_url":"https://codeload.github.com/cold-bin/cb-cache/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cold-bin%2Fcb-cache/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29110559,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-05T03:44:17.043Z","status":"ssl_error","status_checked_at":"2026-02-05T03:44:12.077Z","response_time":65,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: 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":["consistent-hashing","go","kv-store","lru-k-cache"],"created_at":"2024-11-12T04:18:47.542Z","updated_at":"2026-02-05T04:02:02.417Z","avatar_url":"https://github.com/cold-bin.png","language":"Go","readme":"# cb-cache\n\n## introduce\n\n分布式的kv内存数据库\n\n- 缓存获取流程：\n  ![img.png](img.png)\n    - 优先从本地cache获取kv\n    - 如果没获取到，会经由一致性哈希算法找到最近的对等节点,然后获取远端节点的kv并缓存以减少网络请求\n    - 如果还没找到，可以通过`getter`设置k的数据源获取，用以缓存同步\n- 整体架构\n  ![img2.png](img2.png)\n## implementation\n\n- 多节点备份与缓存预热\n- LRU-K策略\n- 一致性哈希\n- singlefilght与并发读写\n  \n## thinking\n\n### 缓存击穿\n\n针对可能发生的缓存击穿问题，只允许同时只有一个协程获取某个key\n\n### lru-k设计\n\nlru-k没啥好说的，主要是在lru的基础上，变更为`history lru data`和`real lru cache`:\n\n- 数据第一次加入缓存，先加入`history lru data`中作为历史数据，只有等访问次数达到`k`时，才会删除并移到`real lru cache`\n- 访问次数达到`k`次的数据以后会被移到真正的缓存里\n\n\u003e lru-k可以很好的解决lru算法的缺陷——lru不能很好地识别到热点数据\n\n### 服务发现与注册\n\n原始groupcache的设计里，节点的离线与上线是无法感知的。于是，便基于etcd实现了服务发现与注册。\n当然consul, zookeeper等组件调用方可以自己实现下面的接口无缝衔接\n\n```go\ntype Client interface {\n\tRegistry\n\tDiscovery\n}\n\ntype Registry interface {\n\tRegister(ctx context.Context, addr string) error\n\tDeregister(ctx context.Context, addr string) error\n}\n\ntype Discovery interface {\n\tGetAddress(ctx context.Context) ([]string, error)\n\tWatch(ctx context.Context) \u003c-chan Event\n}\n\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcold-bin%2Fcb-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcold-bin%2Fcb-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcold-bin%2Fcb-cache/lists"}