{"id":29565584,"url":"https://github.com/michaelwp/lrucache","last_synced_at":"2025-10-06T09:57:07.221Z","repository":{"id":288541870,"uuid":"966518381","full_name":"michaelwp/lrucache","owner":"michaelwp","description":"lrucache is a go Least Recently Used cache library","archived":false,"fork":false,"pushed_at":"2025-04-18T06:58:35.000Z","size":3,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-19T00:42:11.202Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/michaelwp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"zenodo":null}},"created_at":"2025-04-15T03:40:42.000Z","updated_at":"2025-04-18T06:58:09.000Z","dependencies_parsed_at":"2025-04-21T06:47:20.424Z","dependency_job_id":null,"html_url":"https://github.com/michaelwp/lrucache","commit_stats":null,"previous_names":["michaelwp/lrucache"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/michaelwp/lrucache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelwp%2Flrucache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelwp%2Flrucache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelwp%2Flrucache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelwp%2Flrucache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/michaelwp","download_url":"https://codeload.github.com/michaelwp/lrucache/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelwp%2Flrucache/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278591264,"owners_count":26012028,"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-10-06T02:00:05.630Z","response_time":65,"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":[],"created_at":"2025-07-18T21:34:50.602Z","updated_at":"2025-10-06T09:57:07.167Z","avatar_url":"https://github.com/michaelwp.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LRUCache (Least Recently Used Cache)\n\nThis package provides a Go implementation of a **Least Recently Used (LRU)** cache. It offers a simple yet efficient way to store data with quick access, automatically removing the least recently accessed items when the cache reaches its capacity.\n\n## Features\n\n- **O(1) Access and Insertion**: Provides constant-time operations for getting and putting items.\n- **Doubly-Linked List and Map**: Uses an internal map for fast lookups and a doubly-linked list to track item usage.\n- **Generic Value Storage**: Supports storing values of any type (`any`).\n\n## Installation\n\nTo use this package, simply import it into your Go project:\n\n```bash\ngo get github.com/michaelwp/lrucache\n```\n\n## Usage\n\n### Creating a Cache\n\n```go\ncache := lrucache.NewLRUCache(3) // Capacity set to 3\n```\n\n### Adding Items\n\n```go\ncache.Put(\"key1\", \"value1\")\ncache.Put(\"key2\", \"value2\")\ncache.Put(\"key3\", \"value3\")\n```\n\n### Retrieving Items\n\n```go\nvalue := cache.Get(\"key1\") // Moves key1 to most recently used\nfmt.Println(value) // Output: value1\n```\n\n### Cache Eviction\n\nAdding more items beyond the cache capacity evicts the least recently used item:\n\n```go\ncache.Put(\"key4\", \"value4\") // Evicts \"key2\" (if \"key1\" was recently accessed)\n```\n\n### Viewing Cache Content\n\nTo inspect the current content of the cache:\n\n```go\nlist := cache.ViewList()\nfor _, item := range list {\n    fmt.Println(item.Key, item.Value)\n}\n```\n\n## Types and Functions\n\n### Interface `LRUCache`\n\n```go\ntype LRUCache interface {\n\tGet(key string) any\n\tPut(key string, value any)\n\tViewList() []*data\n}\n```\n\n### Functions\n\n- `NewLRUCache(capacity int) LRUCache`: Creates a new cache with a specified capacity.\n\n## Contributing\n\nContributions are welcome! Please open an issue or submit a pull request.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaelwp%2Flrucache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmichaelwp%2Flrucache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaelwp%2Flrucache/lists"}