{"id":34183064,"url":"https://github.com/midy177/cache","last_synced_at":"2026-03-12T13:46:16.427Z","repository":{"id":265192621,"uuid":"895406884","full_name":"midy177/cache","owner":"midy177","description":"Fork from https://github.com/patrickmn/go-cache,and add support for generics.","archived":false,"fork":false,"pushed_at":"2024-11-28T10:45:05.000Z","size":25,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-01-14T13:53:58.830Z","etag":null,"topics":["cahce","generics","golang","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/midy177.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}},"created_at":"2024-11-28T06:37:40.000Z","updated_at":"2024-11-28T10:43:38.000Z","dependencies_parsed_at":"2024-11-28T07:39:49.675Z","dependency_job_id":null,"html_url":"https://github.com/midy177/cache","commit_stats":null,"previous_names":["midy177/go-cache"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/midy177/cache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/midy177%2Fcache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/midy177%2Fcache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/midy177%2Fcache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/midy177%2Fcache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/midy177","download_url":"https://codeload.github.com/midy177/cache/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/midy177%2Fcache/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30427349,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-12T12:46:33.731Z","status":"ssl_error","status_checked_at":"2026-03-12T12:42:20.405Z","response_time":114,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5: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":["cahce","generics","golang","ttl-cache"],"created_at":"2025-12-15T14:22:56.467Z","updated_at":"2026-03-12T13:46:16.419Z","avatar_url":"https://github.com/midy177.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-cache\n\ngo-cache is an in-memory key:value store/cache similar to memcached that is\nsuitable for applications running on a single machine. Its major advantage is\nthat, being essentially a thread-safe `map[string]T` with expiration\ntimes, it doesn't need to serialize or transmit its contents over the network.\n\nAny object can be stored, for a given duration or forever, and the cache can be\nsafely used by multiple goroutines.\n\nAlthough go-cache isn't meant to be used as a persistent datastore, the entire\ncache can be saved to and loaded from a file (using `c.Items()` to retrieve the\nitems map to serialize, and `NewFrom()` to create a cache from a deserialized\none) to recover from downtime quickly. (See the docs for `NewFrom()` for caveats.)\n\n### Installation\n\n`go get github.com/midy177/go-cache`\n\n### Usage\n\n```go\nimport (\n\t\"fmt\"\n\t\"github.com/midy177/go-cache\"\n\t\"time\"\n)\n\nfunc main() {\n\t// Create a cache with a default expiration time of 5 minutes, and which\n\t// purges expired items every 10 minutes\n\tc := cache.New[any](5*time.Minute, 10*time.Minute)\n\n\t// Set the value of the key \"foo\" to \"bar\", with the default expiration time\n\tc.Set(\"foo\", \"bar\", cache.DefaultExpiration)\n\n\t// Set the value of the key \"baz\" to 42, with no expiration time\n\t// (the item won't be removed until it is re-set, or removed using\n\t// c.Delete(\"baz\")\n\tc.Set(\"baz\", 42, cache.NoExpiration)\n\n\t// Get the string associated with the key \"foo\" from the cache\n\tfoo, found := c.Get(\"foo\")\n\tif found {\n\t\tfmt.Println(foo)\n\t}\n\n\t// Since Go is statically typed, and cache values can be anything, type\n\t// assertion is needed when values are being passed to functions that don't\n\t// take arbitrary types, (i.e. interface{}). The simplest way to do this for\n\t// values which will only be used once--e.g. for passing to another\n\t// function--is:\n\tfoo, found := c.Get(\"foo\")\n\tif found {\n\t\tMyFunction(foo.(string))\n\t}\n\n\t// This gets tedious if the value is used several times in the same function.\n\t// You might do either of the following instead:\n\tif x, found := c.Get(\"foo\"); found {\n\t\tfoo := x.(string)\n\t\t// ...\n\t}\n\t// or\n\tvar foo string\n\tif x, found := c.Get(\"foo\"); found {\n\t\tfoo = x.(string)\n\t}\n\t// ...\n\t// foo can then be passed around freely as a string\n\n\t// Want performance? Store pointers!\n\tc.Set(\"foo\", \u0026MyStruct, cache.DefaultExpiration)\n\tif x, found := c.Get(\"foo\"); found {\n\t\tfoo := x.(*MyStruct)\n\t\t\t// ...\n\t}\n}\n```\n\n### Reference\n\n`godoc` or [http://godoc.org/github.com/midy177/go-cache](http://godoc.org/github.com/patrickmn/go-cache)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmidy177%2Fcache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmidy177%2Fcache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmidy177%2Fcache/lists"}