{"id":13713594,"url":"https://github.com/NdoleStudio/lfu-cache","last_synced_at":"2025-05-07T00:31:40.663Z","repository":{"id":57528775,"uuid":"255548979","full_name":"NdoleStudio/lfu-cache","owner":"NdoleStudio","description":"Strongly typed least frequently used (LFU) cache  in Go with constant time complexity O(1) on all operations","archived":false,"fork":false,"pushed_at":"2025-01-30T05:02:50.000Z","size":40,"stargazers_count":9,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-10T17:34:21.057Z","etag":null,"topics":["algorithm","cache","go","lfu-cache","lfu-implementation"],"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/NdoleStudio.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,"zenodo":null}},"created_at":"2020-04-14T08:10:46.000Z","updated_at":"2025-01-30T00:19:04.000Z","dependencies_parsed_at":"2023-12-25T21:33:13.147Z","dependency_job_id":"7b04d4a0-adbb-4796-8b18-ddf68026a8cd","html_url":"https://github.com/NdoleStudio/lfu-cache","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NdoleStudio%2Flfu-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NdoleStudio%2Flfu-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NdoleStudio%2Flfu-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NdoleStudio%2Flfu-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NdoleStudio","download_url":"https://codeload.github.com/NdoleStudio/lfu-cache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252791476,"owners_count":21804778,"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":["algorithm","cache","go","lfu-cache","lfu-implementation"],"created_at":"2024-08-02T23:01:40.030Z","updated_at":"2025-05-07T00:31:40.341Z","avatar_url":"https://github.com/NdoleStudio.png","language":"Go","readme":"Lest Frequently Used (LFU) Cache\n==================================\n[![Build Status](https://travis-ci.com/NdoleStudio/lfu-cache.svg?branch=master)](https://travis-ci.com/NdoleStudio/lfu-cache) \n[![codecov](https://codecov.io/gh/NdoleStudio/lfu-cache/branch/master/graph/badge.svg)](https://codecov.io/gh/NdoleStudio/lfu-cache) \n[![Go Report Card](https://goreportcard.com/badge/github.com/NdoleStudio/lfu-cache)](https://goreportcard.com/report/github.com/NdoleStudio/lfu-cache) \n[![GitHub contributors](https://img.shields.io/github/contributors/NdoleStudio/lfu-cache)](https://github.com/NdoleStudio/lfu-cache/graphs/contributors)\n[![GitHub license](https://img.shields.io/github/license/NdoleStudio/lfu-cache?color=brightgreen)](https://github.com/NdoleStudio/lfu-cache/blob/master/LICENSE)\n[![PkgGoDev](https://pkg.go.dev/badge/github.com/NdoleStudio/lfu-cache)](https://pkg.go.dev/github.com/NdoleStudio/lfu-cache)\n\n\nThis is an in memory implementation of a least frequently used (LFU) cache in Go with constant time complexity O(1) for `Set`, `Set`, and `Cache Eviction` operations. The least recently used item is evicted in the case where 2 items thems have the same least frequency.\n\nIt's based on this paper [http://dhruvbird.com/lfu.pdf](http://dhruvbird.com/lfu.pdf) by some very smart people\n\n## Documentation\n\nYou can use view the standard documentation on  [https://pkg.go.dev/github.com/NdoleStudio/lfu-cache](https://pkg.go.dev/github.com/NdoleStudio/lfu-cache). I wrote a beginner friendly blog post [here](https://acho.arnold.cf/lfu-cache-go/)\n\n## Install\n\n```shell\ngo get https://github.com/NdoleStudio/lfu-cache/v2\n```\n\n## Usage\n\n- To get started, import the `lfu-cache` package and create a cache instance. `New()` returns an `ErrInvalidCap` error  if you input a capacity which is less than or equal to `0`.\n\n    ```go\n    import \"https://github.com/NdoleStudio/lfu-cache/v2\"\n    \n    // creating the cache with capacity 3\n    cache, err := lfucache.New[string, int](3)\n    if err != nil {\n        // the cap is invalid\n    }\n    \n    // DO NOT DO THIS\n    cache := lfucache.Cache{}\n    ```\n\n- Inserting a value in the cache. `Set()` returns `ErrInvalidCap` if the cache capacity is less than or equal to zero. Ideally you should NEVER get this error\n\n    ```go\n    err := cache.Set(\"key\", \"value\")\n    if err != nil {\n        // the cap is invalid\n    }\n    ```\n\n- Getting a value in from the cache. `Get()` returns `ErrCacheMiss` if there is a cache miss\n\n\n    ```go\n    val, err := cache.Get(\"key\")\n    if err != nil {\n        // cache miss\n    }\n    \n    or \n    \n    if err == lfucache.ErrCacheMiss { \n        // cache miss\n    }\n    \n    println(val) // val is of type `int`\n    ```\n\n- There are some helper methods like `IsEmpty()`, `Len()`, `IsFull` `Cap()`\n\n\n    ```go\n    // creating the cache with capacity 3\n    cache, _ := lfucache.New[string, string](3)\n    \n    // setting a value\n    _ = cache.Set(\"key\", \"value\")\n    \n    cache.IsEmpty() // returns false\n    cache.Len()     // returns 1 because there is 1 item in the cache\n    cache.IsFull()  // returns false because the cache is not full\n    cache.Cap()     // returns 3 which is the capacity of the cache\n    ```\n\n### Running Tests\n\nTo run tests, cd to the project directory and run\n\n```bash\ngo test -v \n```\n\n## Versioning\n\nWe use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/NdoleStudio/lfu-cache/tags). \n\n## Authors\n\n* **[AchoArnold](https://github.com/AchoArnold)**\n\nSee also the list of [contributors](https://github.com/NdoleStudio/lfu-cache/contributors) who participated in this project.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details\n","funding_links":[],"categories":["Repositories"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNdoleStudio%2Flfu-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FNdoleStudio%2Flfu-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNdoleStudio%2Flfu-cache/lists"}