{"id":19368457,"url":"https://github.com/anchore/go-cache","last_synced_at":"2025-09-13T05:39:16.738Z","repository":{"id":257783283,"uuid":"857077555","full_name":"anchore/go-cache","owner":"anchore","description":null,"archived":false,"fork":false,"pushed_at":"2025-07-15T20:49:39.000Z","size":29,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-07-16T19:01:35.310Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/anchore.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-09-13T18:54:42.000Z","updated_at":"2025-07-15T20:49:43.000Z","dependencies_parsed_at":null,"dependency_job_id":"fae95af3-648a-49b1-802b-3c02ed4cf3ff","html_url":"https://github.com/anchore/go-cache","commit_stats":null,"previous_names":["anchore/go-cache"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/anchore/go-cache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anchore%2Fgo-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anchore%2Fgo-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anchore%2Fgo-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anchore%2Fgo-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anchore","download_url":"https://codeload.github.com/anchore/go-cache/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anchore%2Fgo-cache/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274920615,"owners_count":25374083,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-13T02:00:10.085Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":"2024-11-10T08:06:28.363Z","updated_at":"2025-09-13T05:39:16.675Z","avatar_url":"https://github.com/anchore.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-cache\n\nA basic caching library.\n\nThis library provides the interfaces used for persistent caching by the Anchore Go CLI tools, including\nSyft and Grype.\n\nEach application should provide means for configuring a `cache.Manager` and\nindividual caches should be obtained from the `cache.Manager`.\n\n## Usage\n\nTo cache specific Go data types, the easiest method is using a `cache.Resolver` with the with automatic type version\nbased on a `cache.HashType` call, which automatically creates a unique version qualifier based on the _structure_ of the provided type.\nThis way, if the structure changes in any way it will end up with a new version key which will invalidate older cache entries\nand result in populating the cache based on this new key.\nThe `cache.Resolver` will store items using the `json` package to serialize/deserialize values, so to save space\nit is encouraged  to use `omitempty`. For example:\n\n```go\ntype myCacheItem struct {\n\tName string `json:\"name\",omitempty`\n}\n```\n\nIf it is common that checking for an item will result in errors, and you do not want to re-run the resolve function\nwhen errors are encountered, instead of using `GetResolver`, you can use `GetResolverCachingErrors`, which is useful\nfor things such as resolving artifacts over a network, where a number of them will not be resolved, and you do not want\nto continue to have the expense of running the network resolution. This should be used when it is acceptable a network\noutage and cached errors is an acceptable risk.\n\nAn example can be seen in the [Syft golang cataloger](https://github.com/anchore/syft/blob/main/syft/pkg/cataloger/golang/licenses.go) fetching remote licenses.\n\n## Example\n\n```golang\npackage appcache\n\nimport \"github.com/anchore/go-cache\"\n\n// default to a bypassed cache, so unit tests are easy to deal with\nvar manager = cache.NewBypassed()\n\n// set the cache after any necessary configuration\nfunc InitCache(dir string, ttl time.Duration) {\n\tmanager = cache.NewFromDir(globalLogger, dir, ttl)\n}\n\n// utility function with an app-scoped global cache\nfunc NewResolver[T any](name string) cache.Resolver[T] {\n\treturn cache.NewResolver[T](manager.GetCache(name, cache.HashType[T]()))\n}\n```\n\n```golang\npackage app\n\nimport \"appcache\"\n\ntype myDataType struct {\n\tValue string `json:\"value,omitempty\"`\n}\n\nvar cacheResolver = appcache.NewResolver[myDataType](\"my-top-level-cache-name\")\n\nfunc functionWhichCaches(someParam string) myDataType {\n\treturn cacheResolver.Resolve(someParam, func() myDataType {\n\t\t// do some work and return \n\t\treturn myDataType{ ... }\n    })\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanchore%2Fgo-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanchore%2Fgo-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanchore%2Fgo-cache/lists"}