{"id":22621664,"url":"https://github.com/larscom/go-cache","last_synced_at":"2026-01-26T01:32:39.809Z","repository":{"id":146421609,"uuid":"617640100","full_name":"larscom/go-cache","owner":"larscom","description":"High performance, simple generic cache written in GO, including a loading cache","archived":false,"fork":false,"pushed_at":"2025-12-16T11:51:33.000Z","size":71,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-19T02:14:23.836Z","etag":null,"topics":["api","cache","cache-loader","concurrent","fast","generic","go","golang","goroutine","http","loader","loading-cache","map","memory","performance","thread-safe","time-to-live","ttl"],"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/larscom.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-03-22T20:00:27.000Z","updated_at":"2025-12-16T11:51:11.000Z","dependencies_parsed_at":"2023-12-23T16:00:45.276Z","dependency_job_id":"627cfe93-943f-457b-8e99-1e02d0656c2e","html_url":"https://github.com/larscom/go-cache","commit_stats":null,"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"purl":"pkg:github/larscom/go-cache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/larscom%2Fgo-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/larscom%2Fgo-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/larscom%2Fgo-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/larscom%2Fgo-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/larscom","download_url":"https://codeload.github.com/larscom/go-cache/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/larscom%2Fgo-cache/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28763939,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-26T00:37:26.264Z","status":"ssl_error","status_checked_at":"2026-01-26T00:37:25.959Z","response_time":113,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6: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":["api","cache","cache-loader","concurrent","fast","generic","go","golang","goroutine","http","loader","loading-cache","map","memory","performance","thread-safe","time-to-live","ttl"],"created_at":"2024-12-08T23:11:18.244Z","updated_at":"2026-01-26T01:32:39.793Z","avatar_url":"https://github.com/larscom.png","language":"Go","readme":"# GO-CACHE\n\n[![Go Report Card](https://goreportcard.com/badge/github.com/larscom/go-cache)](https://goreportcard.com/report/github.com/larscom/go-cache)\n[![Go Reference](https://pkg.go.dev/badge/github.com/larscom/go-cache.svg)](https://pkg.go.dev/github.com/larscom/go-cache)\n\n\u003e High performance, simple generic cache written in GO, including a `loading` cache.\n\n## 🚀 Install\n\n```sh\ngo get github.com/larscom/go-cache\n```\n\n## 💡 Usage\n\nYou can import `go-cache` using:\n\n```go\nimport (\n    \"github.com/larscom/go-cache\"\n)\n```\n\n## 🫱 Loading cache\n\n\u003e Create a new loading cache with `int` type as key and `string` type as value.\n\nA common use case for this loading cache would be to automatically fetch data from a REST API and store it in cache. This implementation will ensure that the REST API is only called once in a concurrent environment.\n\n```go\nfunc main() {\n  \tloaderFunc := func(key int) (string, error) {\n         // you may want to call your REST API here...\n         return \"Hello World\", nil\n\t  }\n\n    c := cache.NewLoadingCache[int, string](loaderFunc)\n    defer c.Close()\n\n    value, err := c.Load(1)\n    if err != nil {\n      log.Fatal(err)\n    }\n    log.Println(value) // Hello World\n}\n```\n\nWith `TTL` option\n\n\u003e Create a new loading cache with time to live of 10 seconds.\n\nThis allows you to call `Load()` as many times as you want and whenever an entry expires it'll call the `loaderFunc` once.\n\n```go\nfunc main() {\n    c := cache.NewLoadingCache(loaderFunc, cache.WithExpireAfterWrite[int, string](time.Second * 10))\n    defer c.Close()\n}\n```\n\n## 🫱 Cache\n\n\u003e Create a `regular` cache (without `Load` and `Reload` functions) with `TTL`\n\n```go\nfunc main() {\n    c := cache.NewCache[int, string](cache.WithExpireAfterWrite[int, string](time.Second * 10))\n    defer c.Close()\n\n    c.Put(1, \"Hello World\")\n\n    value, found := c.Get(1)\n    if found {\n       log.Println(value) // Hello World\n    }\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flarscom%2Fgo-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flarscom%2Fgo-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flarscom%2Fgo-cache/lists"}