{"id":29848534,"url":"https://github.com/j4nn0/go-cache","last_synced_at":"2026-07-01T15:32:22.689Z","repository":{"id":182905652,"uuid":"669268250","full_name":"J4NN0/go-cache","owner":"J4NN0","description":"Thread safe in-memory key-value cache library for Go suitable for single instance microservices","archived":false,"fork":false,"pushed_at":"2023-09-06T21:33:25.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-09-06T11:53:08.931Z","etag":null,"topics":["cache","cache-storage","go","golang","key-value","key-value-store","library","single-instance","single-instance-app","thread-safe"],"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/J4NN0.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":"2023-07-21T19:09:37.000Z","updated_at":"2023-09-02T20:56:57.000Z","dependencies_parsed_at":"2025-07-29T19:31:44.178Z","dependency_job_id":"c8e9d18a-efd6-46f9-95b5-46a339c1127f","html_url":"https://github.com/J4NN0/go-cache","commit_stats":null,"previous_names":["j4nn0/go-cache"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/J4NN0/go-cache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/J4NN0%2Fgo-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/J4NN0%2Fgo-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/J4NN0%2Fgo-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/J4NN0%2Fgo-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/J4NN0","download_url":"https://codeload.github.com/J4NN0/go-cache/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/J4NN0%2Fgo-cache/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35013181,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-01T02:00:05.325Z","response_time":130,"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":["cache","cache-storage","go","golang","key-value","key-value-store","library","single-instance","single-instance-app","thread-safe"],"created_at":"2025-07-29T19:25:04.215Z","updated_at":"2026-07-01T15:32:22.678Z","avatar_url":"https://github.com/J4NN0.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-cache\n\nA thread safe in-memory key-value cache suitable for single instance microservices. Any object can be stored with a given duration or no expiration time at all. Since the cache is thread safe, it can be safely used by multiple goroutines.\n\n# Installation\n\n    go get github.com/J4NN0/go-cache\n\n# Usage\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\tcache \"github.com/J4NN0/go-cache\"\n)\n\nfunc main() {\n\t// Create a cache with a default expiration time of 10 minutes, and which\n\t// purges expired items every 1 second\n\tc := cache.NewCache(10*time.Minute, 1*time.Second)\n\tdefer c.Stop()\n\n\t// Set a new entry with key \"foo\" and value \"someValue\", with the default \n\t// expiration time prior set (i.e. 10 minutes)\n\tc.Set(\"foo\", \"someValue\", cache.DefaultExpiration)\n\n\t// Add a new entry - if an item doesn't already exist for the given key -  \n\t// with key \"bar\" and value \"1\", with no expiration time\n\terr := c.Add(\"bar\", 1, cache.NoExpiration)\n\tif err != nil {\n\t\tfmt.Printf(\"Could not add 'bar': %v\\n\", err)\n\t\treturn\n\t}\n\t\n\t// Replace an existing entry only if it hasn't expired yet\n\terr = c.Replace(\"foo\", \"someValue2\", cache.DefaultExpiration)\n\tif err != nil {\n\t\tfmt.Printf(\"Could not replace 'foo': %v\\n\", err)\n\t\treturn\n\t}\n\n\t// Since Go is statically typed, and cache values can be anything, type\n\t// assertion might be needed in some case\n\tvar foo string\n\tx, found := c.Get(\"foo\")\n\tif !found {\n\t\tfmt.Printf(\"Could not find 'foo'\\n\")\n\t\treturn\n\t}\n\tfoo = x.(string)\n\tfmt.Printf(\"Got 'foo': %s\\n\", foo) // someValue2\n\n\t// Current cache size can be checked with following method\n\tic := c.ItemCount()\n\tfmt.Printf(\"Current cache size: %d\\n\", ic) // 2\n\n\t// Entry can be deleted before it will expire\n\t// (i.e. 10 minutes after being set in this case)\n\tc.Delete(\"foo\")\n\n\t// Delete entire cache content\n\tc.Flush()\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fj4nn0%2Fgo-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fj4nn0%2Fgo-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fj4nn0%2Fgo-cache/lists"}