{"id":17309993,"url":"https://github.com/metafates/gache","last_synced_at":"2025-03-27T00:24:36.406Z","repository":{"id":62866749,"uuid":"560376943","full_name":"metafates/gache","owner":"metafates","description":"🗃️ Dead simple caching library for go","archived":false,"fork":false,"pushed_at":"2022-11-01T18:43:36.000Z","size":20,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-01T06:12:44.091Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/metafates/gache","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/metafates.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":"2022-11-01T11:11:56.000Z","updated_at":"2024-11-26T15:16:55.000Z","dependencies_parsed_at":"2022-11-08T06:15:26.672Z","dependency_job_id":null,"html_url":"https://github.com/metafates/gache","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metafates%2Fgache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metafates%2Fgache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metafates%2Fgache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metafates%2Fgache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/metafates","download_url":"https://codeload.github.com/metafates/gache/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245757169,"owners_count":20667300,"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","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-10-15T12:34:17.448Z","updated_at":"2025-03-27T00:24:36.387Z","avatar_url":"https://github.com/metafates.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Gache \n\nGache is a dead simple file-based (or in-memory) cache library for Go with zero dependencies.\n\nThere are great caching libraries out there, but none of them fit my needs or not as simple as I'd like to.\nSo I decided to write my own and share it with the world. 🐳\n\n## Installation\n\n```bash\ngo get github.com/metafates/gache\n```\n\n## Docs\n\n[Godoc](https://pkg.go.dev/github.com/metafates/gache)\n\n## Usage Example\n\n```go\npackage main\n\nimport (\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"github.com/metafates/gache\"\n\t\"net/http\"\n\t\"time\"\n)\n\ntype Pokemon struct {\n\tHeight int\n}\n\n// Create new cache instance\nvar cache = gache.New[map[string]*Pokemon](\u0026gache.Options{\n\t// Path to cache file\n\t// If not set, cache will be in-memory\n\tPath: \".cache/pokemons.json\",\n\n\t// Lifetime of cache.\n\t// If not set, cache will never expire\n\tLifetime: time.Hour,\n})\n\n// getPokemon will get a pokemon by name from API\n// Gonna Cache Em' All!\nfunc getPokemon(name string) (*Pokemon, error) {\n\t// check if Pokémon is in cache\n\tpokemons, expired, err := cache.Get()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\t\n\tif pokemons == nil {\n\t    pokemons = make(map[string]*Pokemon)\n\t}\n\n\t// if cache is expired, or Pokémon wasn't cached\n\t// Fetch it from API\n\tif pokemon, ok := pokemons[name]; !expired \u0026\u0026 ok {\n\t\treturn pokemon, nil\n\t}\n\n\t// bla-bla-bla, boring stuff, etc...\n\tresp, err := http.Get(\"https://pokeapi.co/api/v2/pokemon/\" + name)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tdefer resp.Body.Close()\n\n\tvar pokemon Pokemon\n\tif err := json.NewDecoder(resp.Body).Decode(\u0026pokemon); err != nil {\n\t\treturn nil, err\n\t}\n\n\t// okay, we got our Pokémon, let's cache it\n\tpokemons[name] = \u0026pokemon\n\t_ = cache.Set(pokemons)\n\n\treturn \u0026pokemon, nil\n}\n\nfunc main() {\n\tstart := time.Now()\n\tfor i := 0; i \u003c 3; i++ {\n\t\t_, _ = getPokemon(\"pikachu\")\n\t}\n\tfmt.Println(time.Since(start))\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmetafates%2Fgache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmetafates%2Fgache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmetafates%2Fgache/lists"}