{"id":48424099,"url":"https://github.com/bbdshow/gocache","last_synced_at":"2026-04-06T09:09:24.215Z","repository":{"id":57482440,"uuid":"155677026","full_name":"bbdshow/gocache","owner":"bbdshow","description":"一款简易的内存缓存实现，支持容量控制，TTL和数据落盘。","archived":false,"fork":false,"pushed_at":"2021-09-03T06:36:17.000Z","size":53,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-08-14T12:41:04.542Z","etag":null,"topics":["cache","golang","memory-cache","ttl-cache"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bbdshow.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-11-01T07:19:27.000Z","updated_at":"2023-07-16T06:07:26.000Z","dependencies_parsed_at":"2022-09-02T06:21:34.041Z","dependency_job_id":null,"html_url":"https://github.com/bbdshow/gocache","commit_stats":null,"previous_names":["huzhongqing/gocache","hopingtop/gocache"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/bbdshow/gocache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbdshow%2Fgocache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbdshow%2Fgocache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbdshow%2Fgocache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbdshow%2Fgocache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bbdshow","download_url":"https://codeload.github.com/bbdshow/gocache/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbdshow%2Fgocache/sbom","scorecard":{"id":227857,"data":{"date":"2025-08-11","repo":{"name":"github.com/bbdshow/gocache","commit":"db5ec942d800d4f3edec700089ac835dbe383e9c"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-17T04:10:03.913Z","repository_id":57482440,"created_at":"2025-08-17T04:10:03.913Z","updated_at":"2025-08-17T04:10:03.913Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31466228,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-06T08:36:52.050Z","status":"ssl_error","status_checked_at":"2026-04-06T08:36:51.267Z","response_time":112,"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":["cache","golang","memory-cache","ttl-cache"],"created_at":"2026-04-06T09:09:23.604Z","updated_at":"2026-04-06T09:09:24.209Z","avatar_url":"https://github.com/bbdshow.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gocache\n\n[![Build Status](https://www.travis-ci.com/bbdshow/gocache.svg?branch=master)](https://travis-ci.org/bbdshow/gocache)\n[![codecov](https://codecov.io/gh/bbdshow/gocache/branch/master/graph/badge.svg)](https://codecov.io/gh/bbdshow/gocache)\n[![Go Report Card](https://goreportcard.com/badge/github.com/bbdshow/gocache)](https://goreportcard.com/report/github.com/bbdshow/gocache)\n\n\u003e 一款简易的内存缓存实现，支持容量控制，TTL和数据落盘。\n\n## 特性\n1. Store接口使用 sync.Map 和 读写锁+MAP 两种实现\n2. 采用 sync.Map 实现， 在多核，大量读取，锁竞争多的情况下存在优势，缺点是内存占用高，空间换时间。 \n3. 支持容量限制，超过容量报错\n3. 支持重启程序加载缓存内容，简单防止因重启导致的缓存击穿。\n4. 支持 TTL Key \n\n## 接口方法\n```go\npackage gocache\n\ntype Cache interface {\n\tGet(key string) (value interface{}, exists bool)                      //\n\tGetWithExpire(key string) (value interface{}, ttl int64, exists bool) // 返回值和剩余时间\n\tSet(key string, value interface{}) error                              //\n\tSetWithExpire(key string, value interface{}, ttl int64) error         // ttl 秒级别\n\tKeys(prefix string) Keys                                              // prefix - 前缀查询，\"\" 查询所有， 只返回当前有效的key\n\tDelete(key string)                                                    //\n\tSize() int64                                                          // 当前存储的数据量\n\tFlushAll()                                                            // 删除所有 key\n\tGobRegister(v ...interface{})                                         // 注册自定义结构体\n\tWriteToDisk() error                                                   // 写入数据到磁盘， 如果存在自定义结构类型，在使用时 一定要先注册结构\n\tLoadFromDisk() error                                                  // 从磁盘加载数据\n\tClose()                                                               //\n}\n\ntype Keys interface {\n\tSize() int64\n\tValue() []string\n}\n\ntype Store interface {\n\tLoad(key string) (value interface{}, ok bool)\n\tStore(key string, value interface{})\n\tDelete(key string)\n\tLoadOrStore(key string, value interface{}) (actual interface{}, loaded bool)\n\tExists(key string) bool\n\tRange(f func(k string, v interface{}) bool)\n\tSize() int64\n\tFlush()\n}\n```\n\n## Usage\n\n\u003e go get github.com/bbdshow/gocache\n\n\u003e 请查看 example 目录\n\n## Notice \n\n- 选择 sync.Map 的实现方式需要 golang 1.11^\n- master 分支为开发分支，最新版本\n\n## FAQ\n\n### 选择 sync.Map 实现 \n\n利用 sync.map 达到读取性能相对更高，sync.Map 并不太适应大量写入的缓存操作, 且因为计数使用了 LoadOrStrore 对 key 计数。\nsync.Map 在内存空间上并不占优势，约 rwMutex + map 的2倍。\n\n在 4 核以内的机器上锁竞争不明显， 所以 RwMutex map 在性能上更占优势，但是当 cpu 核数 往上时， 锁竞争变大， sync.Map 的优势就体现出来了。\n性能测试 引用 https://medium.com/@deckarep/the-new-kid-in-town-gos-sync-map-de24a6bf7c2c\n\n### 选择 rwMutex + map 实现\n\n读写都比较均衡，同时内存占用比 sync.Map 约小1倍，如果读读取要求不强烈。建议选择此实现方式。\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbbdshow%2Fgocache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbbdshow%2Fgocache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbbdshow%2Fgocache/lists"}