{"id":22683246,"url":"https://github.com/mtchavez/lfu","last_synced_at":"2025-03-29T14:27:54.908Z","repository":{"id":26673110,"uuid":"30129721","full_name":"mtchavez/lfu","owner":"mtchavez","description":"LFU Cache in Go/Golang","archived":false,"fork":false,"pushed_at":"2018-11-01T00:26:04.000Z","size":28,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-04T15:32:33.565Z","etag":null,"topics":["cache","go","golang","lfu-cache"],"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/mtchavez.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2015-01-31T23:12:25.000Z","updated_at":"2018-11-06T14:51:32.000Z","dependencies_parsed_at":"2022-08-31T17:01:32.493Z","dependency_job_id":null,"html_url":"https://github.com/mtchavez/lfu","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtchavez%2Flfu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtchavez%2Flfu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtchavez%2Flfu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtchavez%2Flfu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mtchavez","download_url":"https://codeload.github.com/mtchavez/lfu/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246195620,"owners_count":20738909,"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":["cache","go","golang","lfu-cache"],"created_at":"2024-12-09T21:11:22.718Z","updated_at":"2025-03-29T14:27:54.881Z","avatar_url":"https://github.com/mtchavez.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LFU Cache\n\n[![Latest Version](http://img.shields.io/github/release/mtchavez/lfu.svg?style=flat-square)](https://github.com/mtchavez/lfu/releases)\n[![Build Status](https://travis-ci.org/mtchavez/lfu.svg)](https://travis-ci.org/mtchavez/lfu)\n[![Go Documentation](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)](http://godoc.org/github.com/mtchavez/lfu)\n[![Go Report Card](https://goreportcard.com/badge/github.com/mtchavez/lfu)](https://goreportcard.com/report/github.com/mtchavez/lfu)\n[![Maintainability](https://api.codeclimate.com/v1/badges/97808771ae80f01c8c65/maintainability)](https://codeclimate.com/github/mtchavez/lfu/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/97808771ae80f01c8c65/test_coverage)](https://codeclimate.com/github/mtchavez/lfu/test_coverage)\n\nLFU cache in Go offering O(1) Get and Insert [outlined here](http://dhruvbird.com/lfu.pdf).\n\n## Install\n\n`go get -u github.com/mtchavez/lfu`\n\n## Usage\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"github.com/mtchavez/lfu\"\n)\n\nfunc main() {\n    cache := lfu.NewLFU()\n\n    // Insert\n    cache.Insert(42, []byte(\"user:42:user@example.com\"))\n\n    // Insert existing key\n    success, err := cache.Insert(42, \"Nope\")\n    if !success {\n        fmt.Println(\"Error inserting:\", err)\n    }\n\n    var data interface{}\n    var e error\n    // Get\n    data, e = cache.Get(42)\n    fmt.Println(\"Data for 42 is\", data)\n\n    // Get not found\n    data, e = cache.Get(987654321)\n    if e != nil {\n        fmt.Println(\"Error on get:\", e)\n    }\n}\n\n```\n\n## Tests\n\n`go test --cover`\n\n## Benhcmarks\n\nGet and insert methods are benchmarked. Results from OS X with\na 2.3 GHz Intel Core i7 on `go version go1.8.3 darwin/amd64`\n\n```\n# Updated: 2017-08-15\n\nBenchmarkInsert-8                1000000              1860 ns/op\nBenchmarkParallelInsert-8        1000000              1861 ns/op\nBenchmarkGet_EmptyCache-8        5000000               362 ns/op\nBenchmarkGet_AllMisses-8         3000000               732 ns/op\nBenchmarkGet_AllHits-8           1000000              1417 ns/op\nBenchmarkParallelGet-8           2000000              1405 ns/op\n```\n\n## TODO\n\n* Some kind of eviction\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmtchavez%2Flfu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmtchavez%2Flfu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmtchavez%2Flfu/lists"}