{"id":34226121,"url":"https://github.com/ridgelines/go-cache","last_synced_at":"2026-03-11T09:03:26.342Z","repository":{"id":57497049,"uuid":"94466130","full_name":"ridgelines/go-cache","owner":"ridgelines","description":"Thread-safe in-memory cache for go","archived":false,"fork":false,"pushed_at":"2023-01-13T20:42:25.000Z","size":17,"stargazers_count":14,"open_issues_count":0,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-12-19T05:42:04.624Z","etag":null,"topics":["cache","go","golang"],"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/ridgelines.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":"2017-06-15T18:07:43.000Z","updated_at":"2024-04-25T16:58:14.000Z","dependencies_parsed_at":"2023-02-09T17:02:51.502Z","dependency_job_id":null,"html_url":"https://github.com/ridgelines/go-cache","commit_stats":null,"previous_names":["zpatrick/go-cache"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ridgelines/go-cache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ridgelines%2Fgo-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ridgelines%2Fgo-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ridgelines%2Fgo-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ridgelines%2Fgo-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ridgelines","download_url":"https://codeload.github.com/ridgelines/go-cache/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ridgelines%2Fgo-cache/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30376783,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-11T06:09:32.197Z","status":"ssl_error","status_checked_at":"2026-03-11T06:09:17.086Z","response_time":84,"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","go","golang"],"created_at":"2025-12-16T00:19:52.950Z","updated_at":"2026-03-11T09:03:26.336Z","avatar_url":"https://github.com/ridgelines.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Go Cache\n\n[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/ridgelines/go-cache/blob/master/LICENSE)\n[![Go Report Card](https://goreportcard.com/badge/github.com/ridgelines/go-cache)](https://goreportcard.com/report/github.com/ridgelines/go-cache)\n[![Go Doc](https://godoc.org/github.com/ridgelines/go-cache?status.svg)](https://godoc.org/github.com/ridgelines/go-cache)\n\n\n## Overview\nGo Cache is a simple package to provide thread-safe in-memory caching in Go. \nIt's my attempt to practice some of the patterns/philosophies found in these articles:\n\n* [Do not fear first class functions](https://dave.cheney.net/2016/11/13/do-not-fear-first-class-functions)\n* [Share Memory By Communicating](https://blog.golang.org/share-memory-by-communicating)\n\nThe code is [tested](https://github.com/ridgelines/go-cache/blob/master/cache_test.go), although standard caveats of using `interface{}` apply.  \nPersonally, I'd recommend copying this package and replacing `var T interface{}` with whatever type you need to cache. \nI may add code generation in the future to make that process easier. \n\n## Example\n```\npackage main\n\nimport (\n        \"fmt\"\n\t\"time\"\n        \"github.com/ridgelines/go-cache\"\n)\n\nfunc main() {\n\tc := cache.New()\n\t\n\t// empty the cache every hour\n\tc.ClearEvery(time.Hour)\n\t\n\t// add some items\n\tc.Set(\"key1\", 1)\n\tc.Set(\"key2\", 2)\n\t\n\t// add some items that will expire after 5 minutes\n\tc.Set(\"key3\", 3, cache.Expire(time.Minute*5))\n\tc.Set(\"key4\", 4,  cache.Expire(time.Minute*5))\n\n\tfmt.Println(c.Get(\"key1\"))\n\tfmt.Println(c.Get(\"key2\"))\n\t\n\tfor _, key := range c.Keys() {\n\t\tfmt.Println(key)\n\t}\n\t\n\tfor key, val := range c.Items() {\n\t\tfmt.Printf(\"%s: %v\", key, val)\n\t}\n\t\n\tc.Delete(\"key1\")\n\t\n\tif val, ok := c.GetOK(\"key2\"); ok {\n\t\tfmt.Println(val)\n\t}\n\t\n\tc.Clear()\n}\n```\n\n## License\nThis work is published under the MIT license.\nPlease see the `LICENSE` file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fridgelines%2Fgo-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fridgelines%2Fgo-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fridgelines%2Fgo-cache/lists"}