{"id":39173387,"url":"https://github.com/secnot/simplelru","last_synced_at":"2026-01-17T22:25:26.679Z","repository":{"id":77994505,"uuid":"94881430","full_name":"secnot/simplelru","owner":"secnot","description":"LRU Cache implementation written in Go","archived":false,"fork":false,"pushed_at":"2017-08-08T09:48:32.000Z","size":40,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-06-20T15:40:23.736Z","etag":null,"topics":["cache","concurrent","go","golang","lru","lru-cache","simplelru"],"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/secnot.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":"2017-06-20T10:55:44.000Z","updated_at":"2020-11-04T08:37:05.000Z","dependencies_parsed_at":"2023-02-25T14:46:32.526Z","dependency_job_id":null,"html_url":"https://github.com/secnot/simplelru","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/secnot/simplelru","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/secnot%2Fsimplelru","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/secnot%2Fsimplelru/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/secnot%2Fsimplelru/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/secnot%2Fsimplelru/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/secnot","download_url":"https://codeload.github.com/secnot/simplelru/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/secnot%2Fsimplelru/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28520372,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T22:11:28.393Z","status":"ssl_error","status_checked_at":"2026-01-17T22:11:27.841Z","response_time":85,"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":["cache","concurrent","go","golang","lru","lru-cache","simplelru"],"created_at":"2026-01-17T22:25:26.020Z","updated_at":"2026-01-17T22:25:26.673Z","avatar_url":"https://github.com/secnot.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SimpleLRU  [![Build Status](https://travis-ci.org/secnot/simplelru.svg?branch=master)](https://travis-ci.org/secnot/simplelru) [![GoDoc](https://godoc.org/github.com/secnot/simplelru?status.svg)](http://godoc.org/github.com/secnot/simplelru) [![Go Report Card](https://goreportcard.com/badge/github.com/secnot/simplelru)](https://goreportcard.com/report/github.com/secnot/simplelru) \n\nA LRU Cache (Least Recently Used) written in Go.\n\n- Concurrency-safe\n- Supports auto-fetching for items on cache miss.\n- 100% Test coverage\n\n\n## Installation\n\nDownload the package and its only dependency:\n\n```bash\ngo get github.com/secnot/simplerlu\n```\n\n## Usage\n\nA basic LRU cache:\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/secnot/simplelru\"\n)\n\nfunc main() {\n\n\tmaxCacheSize := 1000\n\tpruneSize := 10\n\n\tcache := simplelru.NewLRUCache(maxCacheSize, pruneSize)\n\n\t// Add or update cache items with Set\n\tcache.Set(\"John Smith\", 32)\n\tcache.Set(\"John Smith\", 33)\n\n\t// Use Get to retrieve item value\n\tif value, ok := cache.Get(\"Little Pony\") {\n\t\tfmt.Println(\"Little Pony isn't cached\")\n\t}\n\n\t// How many items are in the cache\n\tfmt.Printf(\"There are %v cached items\\n\", cache.Len())\n\n\t// John Smith looks like a fake name better remove it\n\tcache.Remove(\"John Smith\")\n}\n```\n\nOr with a function to fetch the value from another source on cache miss:\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/secnot/simplelru\"\n)\n\nconst (\n\tmaxCacheSize = 10000\n\tpruneSize = 100\n\tfetchWorkers = 2\n\tfetchQueueSize = fetchWorkers * 2\n)\n\n\n// Simulated db query, with delay (concurrency-safe)\nfunc mockDBFetch(key interface{}) (value interface{}, ok bool) {\n\ttime.Sleep(20 * time.Millisecond)\n\treturn fmt.Sprintf(\"query result: %v\", key), true\n}\n\n\nfunc main() {\n\n\tcache := simplelru.NewFetchingLRUCache(\n\t\tmaxCacheSize,\n\t\tpruneSize,\n\t\tmockDBFetch,\n\t\tfetchWorkers,\n\t\tfetchQueueSize)\n\n\t// If a key is not cached there is a fetch\n\tvalue, _ := cache.Get(1) // Ignore errors\n\tfmt.Println(value) // \u003e query result: 1\n\n\t// No fetch for cached keys\n\tcache.Set(2, \"2 is cached\")\n\tvalue, _ = cache.Get(2) // Ignore errors\n\tfmt.Println(value) // \u003e 2 is cached\n}\n``` \n\n## Documentation\n\nThe full API documentation is available at [GoDoc](http://godoc.org/github.com/secnot/simplelru).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsecnot%2Fsimplelru","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsecnot%2Fsimplelru","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsecnot%2Fsimplelru/lists"}