{"id":13411841,"url":"https://github.com/cheshir/ttlcache","last_synced_at":"2025-12-30T03:49:48.091Z","repository":{"id":40500278,"uuid":"327409335","full_name":"cheshir/ttlcache","owner":"cheshir","description":"Simple in-memory key-value storage with TTL for each record.","archived":false,"fork":false,"pushed_at":"2022-10-02T17:36:34.000Z","size":30,"stargazers_count":9,"open_issues_count":0,"forks_count":8,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-07-31T20:49:02.241Z","etag":null,"topics":["cache","cache-storage","go","golang","hacktoberfest","inmemory-cache","key-value","ttl-cache","ttl-cache-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/cheshir.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}},"created_at":"2021-01-06T19:24:26.000Z","updated_at":"2023-03-26T17:03:11.000Z","dependencies_parsed_at":"2022-08-09T22:14:33.786Z","dependency_job_id":null,"html_url":"https://github.com/cheshir/ttlcache","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cheshir%2Fttlcache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cheshir%2Fttlcache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cheshir%2Fttlcache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cheshir%2Fttlcache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cheshir","download_url":"https://codeload.github.com/cheshir/ttlcache/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243618670,"owners_count":20320274,"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","cache-storage","go","golang","hacktoberfest","inmemory-cache","key-value","ttl-cache","ttl-cache-implementation"],"created_at":"2024-07-30T20:01:17.474Z","updated_at":"2025-12-30T03:49:48.064Z","avatar_url":"https://github.com/cheshir.png","language":"Go","readme":"[![Build Status](https://github.com/cheshir/ttlcache/actions/workflows/go.yml/badge.svg)](https://github.com/cheshir/ttlcache/actions/workflows/go.yml)\n[![codecov](https://codecov.io/gh/cheshir/ttlcache/branch/main/graph/badge.svg?token=WsaH2t9dGh)](https://codecov.io/gh/cheshir/ttlcache)\n[![Go Report Card](https://goreportcard.com/badge/cheshir/ttlcache)](https://goreportcard.com/report/github.com/cheshir/ttlcache)\n[![GoDoc](https://godoc.org/github.com/cheshir/ttlcache?status.svg)](https://godoc.org/github.com/cheshir/ttlcache)\n[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge-flat.svg)](https://github.com/avelino/awesome-go)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/cheshir/go-mq/blob/master/LICENSE)\n\n# ttlcache\n\n## About\n\n**ttlcache** – is a simple and efficient in-memory key value storage with TTL for each record.\n\nThe key is of uint64 type. Library provides wrappers for common types:\n\n* IntKey\n* ByteKey\n* Int8Key\n* Uint8Key\n* Int16Key\n* Uint16Key\n* Int32Key\n* Uint32Key\n* Int64Key\n* Uint64Key\n* BytesKey ([]byte)\n* StringKey\n* AnyKey (interface{})\n\n`AnyKey` is not suitable for _very_ intensive usage. Consider writing your own hash function if your keys are complex types, \nand you faced performance degradation.\n\n## Installation\n\n`go get -u github.com/cheshir/ttlcache`\n\n## Usage\n\n```go\npackage main\n\nimport (\n    \"github.com/cheshir/ttlcache\"\n)\n\nconst (\n    minute = 60 * time.Second\n    hour = 60 * minute\n)\n\nfunc main() {\n    // How often we need to stop the world and remove outdated records.\n    resolution := minute\n\n    cache := ttlcache.New(resolution)\n    cache.Set(ttlcache.StringKey(\"some key\"), \"value\", hour)\n    value, ok := cache.Get(ttlcache.StringKey(\"some key\"))\n    if !ok {\n        // there is no record with key \"some key\" in the cache. Probably it has been expired.\n    }\n\n    fmt.Println(value.(string)) // This is necessary type assertion, because returned value is of interface{} type.\n}\n```\n\n## Performance\n\nIf you're interested in benchmarks you can check them in repository.\nJust play with numbers and types and check that library is suitable for your purposes.\n\n`go test -bench=. -benchmem`\n\nFor those of us who wants to get some numbers without downloading unknown stuff (MacBook Pro 16\"):\n\n```go\nBenchmarkCache_Set_100-16           8959221               125 ns/op\nBenchmarkCache_Set_1000-16          9177854               123 ns/op\nBenchmarkCache_Set_10000-16         9247304               131 ns/op\nBenchmarkCache_Get_100-16           50562800              23.9 ns/op\nBenchmarkCache_Get_1000-16          47270793              26.9 ns/op\nBenchmarkCache_Get_10000-16         42578484              27.7 ns/op\n\n```\n","funding_links":[],"categories":["Database","数据库","Generators","Data Integration Frameworks","Uncategorized"],"sub_categories":["Caches","缓存","Advanced Console UIs"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcheshir%2Fttlcache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcheshir%2Fttlcache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcheshir%2Fttlcache/lists"}