{"id":19221196,"url":"https://github.com/gozeloglu/cache","last_synced_at":"2025-10-29T15:35:57.496Z","repository":{"id":57638151,"uuid":"428301835","full_name":"gozeloglu/cache","owner":"gozeloglu","description":"LRU-based cache package for Go.","archived":false,"fork":false,"pushed_at":"2024-03-23T18:00:41.000Z","size":52,"stargazers_count":28,"open_issues_count":1,"forks_count":4,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-20T22:32:30.681Z","etag":null,"topics":["cache","go","go-package","golang","lru","lru-cache"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/gozeloglu/cache","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/gozeloglu.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":"2021-11-15T14:42:57.000Z","updated_at":"2024-09-10T14:15:42.000Z","dependencies_parsed_at":"2024-03-23T18:48:45.848Z","dependency_job_id":null,"html_url":"https://github.com/gozeloglu/cache","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gozeloglu%2Fcache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gozeloglu%2Fcache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gozeloglu%2Fcache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gozeloglu%2Fcache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gozeloglu","download_url":"https://codeload.github.com/gozeloglu/cache/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253852320,"owners_count":21973903,"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","go-package","golang","lru","lru-cache"],"created_at":"2024-11-09T14:40:26.885Z","updated_at":"2025-10-29T15:35:52.457Z","avatar_url":"https://github.com/gozeloglu.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cache [![Go Reference](https://pkg.go.dev/badge/github.com/gozeloglu/cache.svg)](https://pkg.go.dev/github.com/gozeloglu/cache) [![Go Report Card](https://goreportcard.com/badge/github.com/gozeloglu/cache)](https://goreportcard.com/report/github.com/gozeloglu/cache) ![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/gozeloglu/cache) ![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/gozeloglu/cache) [![LICENSE](https://img.shields.io/badge/license-MIT-green)](https://github.com/gozeloglu/cache/blob/main/LICENSE)\n\ncache is LRU-based cache package written in vanilla Go - with no package dependency. LRU stands for **Least Recently\nUsed** and it is one of the famous cache replacement algorithm. It replaces newly added data with the least recently\nused one.\n\n* Written in Vanilla Go, with no dependencies.\n* Safe for concurrent use.\n* Supports any data type for keys and values.\n* Supports time expiration.\n\n### Installation\n\n```\ngo get github.com/gozeloglu/cache\n```\n\n### Example\n\nHere, there is an example usage of the package.\n\nYou can import like this.\n\n```go\nimport \"github.com/gozeloglu/cache\"\n```\n\nThen, you need to create a cache variable with `New()` function. It takes one parameter to specify cache capacity.\n\n#### Add new data\n\n```go\ncache.Add(\"foo\", \"bar\", 0) // Without expiration time\ncache.Add(\"key\", \"value\", time.Hour * 2) // With expiration time\n```\n\n#### Get data\n\n```go\nval, found := cache.Get(\"foo\")\nif !found {\n    fmt.Println(\"key does not exist. val is nil.\")\n}\nfmt.Println(val)\n```\n\n#### Get all keys\n\n```go\nkeys := cache.Keys()\nfor _, k := range keys {\n    fmt.Println(k)\n}\n```\n\n#### Contains, Peek and Remove\n\n```go\nfound := cache.Contains(\"foo\")\nif found {\n    val, _ := cache.Peek(\"foo\")\n    cache.Remove(\"foo\")\n}\n```\n\n#### Remove Oldest\n\n```go\nk, v, ok := cache.RemoveOldest()\nif ok {\n    fmt.Printf(\"Oldest key-value pair removed: %s-%s\", k, v)\n}\n```\n\n#### Resize\n\n```go\ncache.Resize(20) // Capacity will be 20\n```\n\n#### Update value, update expiration date, and replace\n\n```go\nnewItem, err := cache.UpdateVal(\"foo\", \"foobar\") // Cache data order is also updated\nif err != nil {\n    fmt.Printf(\"New item key and value is %s-%s\", newItem.Key, newItem.Val)\n}\nnewItem, err := c.UpdateExpirationDate(\"foo\", time.Hour * 4) // Cache data order is also updated\nif err != nil {\n    fmt.Printf(\"%v\", newItem.Expiration)\n}\n\nerr = c.Replace(\"foo\", \"fuzz\")  // Change value of the key without updating cache access order\nif err != nil {\n\tfmt.Printf(err.Error())\n}\n```\n\n### Testing\n\nYou can run the tests with the following command.\n\n```\ngo test .\n```\n\n### Code Coverage\n\nYou can get the code coverage information with the following command:\n\n```bash\ngo test -cover\n```\n\nIf you want to generate a graphical coverage report, you can run the following command:\n\n```bash\ngo tool cover -html=coverage.out\n```\n\nA browser tab will be opened and you will be able to see the graphical report. It shows not tracked, not covered, and covered line on the source code. \n\n### LICENSE\n\n[MIT](https://github.com/gozeloglu/cache/blob/main/LICENSE)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgozeloglu%2Fcache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgozeloglu%2Fcache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgozeloglu%2Fcache/lists"}