{"id":13411835,"url":"https://github.com/zekroTJA/timedmap","last_synced_at":"2025-03-14T17:31:08.421Z","repository":{"id":54106663,"uuid":"168342959","full_name":"zekroTJA/timedmap","owner":"zekroTJA","description":"A thread safe map which has expiring key-value pairs.","archived":false,"fork":false,"pushed_at":"2024-05-05T09:33:30.000Z","size":62,"stargazers_count":72,"open_issues_count":0,"forks_count":10,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-06T22:33:14.287Z","etag":null,"topics":["go","golang","hacktoberfest","library","map","package","time","timemap"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/zekroTJA/timedmap/v2","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/zekroTJA.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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}},"created_at":"2019-01-30T12:55:37.000Z","updated_at":"2025-01-06T10:55:00.000Z","dependencies_parsed_at":"2023-11-29T23:30:49.658Z","dependency_job_id":"ef3dcde8-e3aa-4c65-8733-1069546f468e","html_url":"https://github.com/zekroTJA/timedmap","commit_stats":{"total_commits":63,"total_committers":3,"mean_commits":21.0,"dds":0.06349206349206349,"last_synced_commit":"65747566e4408c2bb0ba6092396d0c0eefe49cdd"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zekroTJA%2Ftimedmap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zekroTJA%2Ftimedmap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zekroTJA%2Ftimedmap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zekroTJA%2Ftimedmap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zekroTJA","download_url":"https://codeload.github.com/zekroTJA/timedmap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243618668,"owners_count":20320273,"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":["go","golang","hacktoberfest","library","map","package","time","timemap"],"created_at":"2024-07-30T20:01:17.383Z","updated_at":"2025-03-14T17:31:07.990Z","avatar_url":"https://github.com/zekroTJA.png","language":"Go","readme":"\u003cdiv align=\"center\"\u003e\n    \u003ch1\u003e~ timedmap ~\u003c/h1\u003e\n    \u003cstrong\u003eA map which has expiring key-value pairs.\u003c/strong\u003e\u003cbr\u003e\u003cbr\u003e\n    \u003ca href=\"https://pkg.go.dev/github.com/zekroTJA/timedmap\"\u003e\u003cimg src=\"https://godoc.org/github.com/zekroTJA/timedmap?status.svg\" /\u003e\u003c/a\u003e\u0026nbsp;\n    \u003ca href=\"https://github.com/zekroTJA/timedmap/actions/workflows/main-ci.yml\" \u003e\u003cimg src=\"https://github.com/zekroTJA/timedmap/actions/workflows/main-ci.yml/badge.svg\" /\u003e\u003c/a\u003e\u0026nbsp;\n    \u003ca href=\"https://coveralls.io/github/zekroTJA/timedmap\"\u003e\u003cimg src=\"https://coveralls.io/repos/github/zekroTJA/timedmap/badge.svg\" /\u003e\u003c/a\u003e\u0026nbsp;\n    \u003ca href=\"https://goreportcard.com/report/github.com/zekroTJA/timedmap\"\u003e\u003cimg src=\"https://goreportcard.com/badge/github.com/zekroTJA/timedmap\"/\u003e\u003c/a\u003e\u0026nbsp;\n\t\u003ca href=\"https://github.com/avelino/awesome-go\"\u003e\u003cimg src=\"https://awesome.re/mentioned-badge.svg\"/\u003e\u003c/a\u003e\n\u003cbr\u003e\n\u003c/div\u003e\n\n---\n\n\u003cdiv align=\"center\"\u003e\n    \u003ccode\u003ego get -u github.com/zekroTJA/timedmap/v2\u003c/code\u003e\n\u003c/div\u003e\n\n---\n\n## Intro\n\nThis package allows to set values to a map which will expire and disappear after a specified time.\n\n[Here](https://pkg.go.dev/github.com/zekroTJA/timedmap/v2) you can read the docs of this package, generated by pkg.go.dev.\n\n\u003e [!IMPORTANT]  \n\u003e The package has been updated to `v2` which will introduce breaking changes to `v1`.\n\u003e - The package now requires a minimum Go version of `v1.19`.\n\u003e - `TimedMap` and corresponding constructor function now take type parameters for key and value types for improved type safety.\n\u003e - Sections have been removed in favor of performance and simplicity of the package.\n\u003e - Previously deprecated functions have been removed.\n\u003e\n\u003e If you experience issues with `v1`, please create an issue with the specific version mentioned. `v1` will still receive updates for bugs and incosistencies alongside `v2`.\n\n---\n\n## Usage Example\n\n```go\npackage main\n\nimport (\n\t\"log\"\n\t\"time\"\n\n\t\"github.com/zekroTJA/timedmap/v2\"\n)\n\nfunc main() {\n\n\t// Creates a new timed map which scans for\n\t// expired keys every 1 second\n\ttm := timedmap.New[string, int](1 * time.Second)\n\n\t// Add a key \"hey\" with the value 213, which should\n\t// expire after 3 seconds and execute the callback, which\n\t// prints that the key was expired\n\ttm.Set(\"hey\", 213, 3*time.Second, func(v int) {\n\t\tlog.Println(\"key-value pair of 'hey' has expired\")\n\t})\n\n\t// Print key \"hey\" from timed map\n\tprintKeyVal(tm, \"hey\")\n\n\t// Wait for 5 seconds\n\t// During this time the main thread is blocked, the\n\t// key-value pair of \"hey\" will be expired\n\ttime.Sleep(5 * time.Second)\n\n\t// Printing value of key \"hey\" wil lfail because the\n\t// key-value pair does not exist anymore\n\tprintKeyVal(tm, \"hey\")\n}\n\nfunc printKeyVal(tm *timedmap.TimedMap[string, int], key string) {\n\td, ok := tm.GetValue(key)\n\tif !ok {\n\t\tlog.Println(\"data expired\")\n\t\treturn\n\t}\n\n\tlog.Printf(\"%v = %d\\n\", key, d)\n}\n```\n\nFurther examples, you can find in the [examples](examples) directory.\n\nIf you want to see this package in a practcal use case scenario, please take a look at the rate limiter implementation of the REST API of [myrunes.com](https://myrunes.com), where I have used `timedmap` for storing client-based limiter instances:  \nhttps://github.com/myrunes/backend/blob/master/internal/ratelimit/ratelimit.go\n\n---\n\nCopyright (c) 2020 zekro Development (Ringo Hoffmann).  \nCovered by MIT licence.\n","funding_links":[],"categories":["Database","Uncategorized","数据库","Generators","Data Structures","Data Integration Frameworks","数据结构`go语言实现的数据结构与算法`","数据结构"],"sub_categories":["Caches","缓存","Advanced Console UIs","标准 CLI"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FzekroTJA%2Ftimedmap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FzekroTJA%2Ftimedmap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FzekroTJA%2Ftimedmap/lists"}