{"id":17910123,"url":"https://github.com/austingebauer/go-lru-cache","last_synced_at":"2025-03-23T20:32:05.177Z","repository":{"id":57607298,"uuid":"214002352","full_name":"austingebauer/go-lru-cache","owner":"austingebauer","description":"A Go library that provides a thread-safe least recently used (LRU) cache with a fixed capacity.","archived":false,"fork":false,"pushed_at":"2020-01-08T06:50:07.000Z","size":32,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-18T23:43:56.657Z","etag":null,"topics":[],"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/austingebauer.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":"2019-10-09T19:09:22.000Z","updated_at":"2020-04-17T14:38:33.000Z","dependencies_parsed_at":"2022-08-30T08:51:34.611Z","dependency_job_id":null,"html_url":"https://github.com/austingebauer/go-lru-cache","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/austingebauer%2Fgo-lru-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/austingebauer%2Fgo-lru-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/austingebauer%2Fgo-lru-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/austingebauer%2Fgo-lru-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/austingebauer","download_url":"https://codeload.github.com/austingebauer/go-lru-cache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245165230,"owners_count":20571269,"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-28T19:29:16.329Z","updated_at":"2025-03-23T20:32:04.902Z","avatar_url":"https://github.com/austingebauer.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-lru-cache [![GoReportCard](https://goreportcard.com/badge/github.com/austingebauer/go-lru-cache)](https://goreportcard.com/report/github.com/austingebauer/go-lru-cache) [![GoDoc](https://godoc.org/github.com/austingebauer/go-lru-cache?status.svg)](https://godoc.org/github.com/austingebauer/go-lru-cache)\n\nA Go library that provides a thread-safe least recently used (LRU) cache with a fixed \ncapacity.\n\n## Installation\n\nTo install `go-lru-cache`, use `go get`.\n\n```bash\ngo get github.com/austingebauer/go-lru-cache\n```\n\nThen import the library into your Go program.\n\n```go\nimport \"github.com/austingebauer/go-lru-cache\"\n```\n\n## Usage\n\n### API\n\n`go-lru-cache` has a simple API.\n\nIt provides a `Put()` method that allows you to place key/value pairs into the cache.\n\nIt provides a `Get()` method that allows you to retrieve values given a key.\n\nIt provides a `Purge()` method that clears the cache.\n\nIt provides a `Len()` method that returns the length of the cache.\n\nPlease see the [GoDoc](https://godoc.org/github.com/austingebauer/go-lru-cache) for \nadditional API documentation of the library.\n\n**Example 1**: Basic usage\n```go\ncache, err := lru.NewCache(2, nil)\n\ncache.Put(1, 2)\ncache.Put(2, 3)\ncache.Get(1)       // returns 2\ncache.Put(3, 4)    // evicts 2-\u003e3\ncache.Get(2)       // returns -1 (not found)\ncache.Put(4, 5)    // evicts 1-\u003e2\ncache.Get(1)       // returns -1 (not found)\ncache.Get(3)       // returns 4\ncache.Get(4)       // returns 5\n```\n\n**Example 2**: Usage showing `onEvict()` function passed into `NewCache()`\n```go\nkeyVal := \"\"\nonEvict := func(key, value interface{}) {\n    keyVal = key.(string) + value.(string)\n}\n\ncache, err := NewCache(1, onEvict)\ncache.Put(\"ada\", \"lovelace\")\ncache.Put(\"linus\", \"torvalds\") // evicts ada-\u003elovelace\n\n// Eviction happened on ada-\u003elovelace, thereby calling onEvict()\n// So, printing keyVal will print \"adalovelace\"\nfmt.Println(keyVal)\n```\n\n### Behavior\n\n`go-lru-cache` will begin to evict the least recently used key/value pair when it has \nreached its given capacity.\n\nCalls to both `Get()` and `Put()` count as usage of a given key/value pair.\n\nIf an `onEvicted` function has been passed into `NewCache()` during construction, then \nthe function will be called with the evicted key/value pair every time an eviction occurs.\n\n## Contributing\n\nPull requests are welcome. \n\nFor major changes, please open an issue first to discuss what you would like to change.\n\nPlease make sure to update tests along with changes.\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faustingebauer%2Fgo-lru-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faustingebauer%2Fgo-lru-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faustingebauer%2Fgo-lru-cache/lists"}