{"id":20388581,"url":"https://github.com/efureev/cache","last_synced_at":"2026-05-07T20:34:50.843Z","repository":{"id":57495651,"uuid":"134817176","full_name":"efureev/cache","owner":"efureev","description":"cache in memory","archived":false,"fork":false,"pushed_at":"2019-09-19T10:02:34.000Z","size":19,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-14T03:34:52.851Z","etag":null,"topics":["cache","memory"],"latest_commit_sha":null,"homepage":null,"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/efureev.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":"2018-05-25T07:06:04.000Z","updated_at":"2022-03-16T19:21:28.000Z","dependencies_parsed_at":"2022-08-31T12:51:37.883Z","dependency_job_id":null,"html_url":"https://github.com/efureev/cache","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/efureev/cache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/efureev%2Fcache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/efureev%2Fcache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/efureev%2Fcache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/efureev%2Fcache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/efureev","download_url":"https://codeload.github.com/efureev/cache/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/efureev%2Fcache/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27440618,"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","status":"online","status_checked_at":"2025-12-01T02:00:06.371Z","response_time":60,"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","memory"],"created_at":"2024-11-15T03:11:40.144Z","updated_at":"2025-12-01T23:06:23.567Z","avatar_url":"https://github.com/efureev.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Codacy Badge](https://api.codacy.com/project/badge/Grade/fcf7f843772443d49541eeef28b93397)](https://app.codacy.com/app/efureev/cache?utm_source=github.com\u0026utm_medium=referral\u0026utm_content=efureev/cache\u0026utm_campaign=Badge_Grade_Dashboard)\n[![Build Status](https://travis-ci.org/efureev/cache.svg?branch=master)](https://travis-ci.org/efureev/cache)\n[![Maintainability](https://api.codeclimate.com/v1/badges/baa3f34d41f82f4510ce/maintainability)](https://codeclimate.com/github/efureev/cache/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/baa3f34d41f82f4510ce/test_coverage)](https://codeclimate.com/github/efureev/cache/test_coverage)\n[![Go Report Card](https://goreportcard.com/badge/github.com/efureev/cache)](https://goreportcard.com/report/github.com/efureev/cache)\n[![codecov](https://codecov.io/gh/efureev/cache/branch/master/graph/badge.svg)](https://codecov.io/gh/efureev/cache)\n\n# cache\n\ncache is an in-memory key:value store/cache for applications running on a single machine. \nIts major advantage is that, being essentially a thread-safe `map[string]interface{}` 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\n### Installation\n\n`go get -u github.com/efureev/cache/v2`\n\n### Usage\n\n```go\npackage main\nimport (\n\t\"fmt\"\n\t\"github.com/efureev/cache/v2\"\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(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\tc.Set(333, \"bar\", cache.DefaultExpiration)\n\tpnt = true\n\tc.Set(\u0026pnt, \"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(333, 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(bar.(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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fefureev%2Fcache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fefureev%2Fcache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fefureev%2Fcache/lists"}