{"id":16413406,"url":"https://github.com/mkelcik/memory-cache","last_synced_at":"2025-10-11T07:14:54.472Z","repository":{"id":206298948,"uuid":"716303753","full_name":"mkelcik/memory-cache","owner":"mkelcik","description":"in memory cache package","archived":false,"fork":false,"pushed_at":"2024-03-27T10:04:27.000Z","size":17,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-06T09:29:09.359Z","etag":null,"topics":["cache","go","golang","memory-cache","thread-safe","ttl","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/mkelcik.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":"2023-11-08T21:20:16.000Z","updated_at":"2023-11-23T20:57:36.000Z","dependencies_parsed_at":"2024-03-27T11:27:11.752Z","dependency_job_id":"718676f6-afcd-4408-84e4-dd624b2be9f0","html_url":"https://github.com/mkelcik/memory-cache","commit_stats":null,"previous_names":["mkelcik/memory-cache"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkelcik%2Fmemory-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkelcik%2Fmemory-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkelcik%2Fmemory-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkelcik%2Fmemory-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mkelcik","download_url":"https://codeload.github.com/mkelcik/memory-cache/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240441508,"owners_count":19801789,"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","memory-cache","thread-safe","ttl","ttl-cache","ttl-cache-implementation"],"created_at":"2024-10-11T06:51:25.704Z","updated_at":"2025-10-11T07:14:49.422Z","avatar_url":"https://github.com/mkelcik.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Simple thread save memory cache\n\nFeatures:\n* generic\n* thread save\n* TTL\n* optional fixed size (after defined capacity is reached, oldest element is distracted)\n* async GC of expired keys\n\n### How to use\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\tmcache \"github.com/mkelcik/memory-cache\"\n\t\"time\"\n)\n\ntype CacheValue struct {\n\tValue int\n}\n\nfunc main() {\n\t// define type of key and value\n\t// first parameter is pre allocation size\n\t// if second parameter is true, cache is limited to this size, if false the cache can grow beyond this capacity\n\t// third parameter is ttl duration for records, if is set to 0 the cache items never expire\n\t// last parameter is GC interval in seconds, if set to 0, GC will never start automatically\n\tcache := mcache.NewCache[int, CacheValue](100, false, 60 * time.Second, 120 * time.Second)\n\n\t// set data to cache\n\tfor i := 1; i \u003c= 100; i++ {\n\t\tcache.Set(i, CacheValue{Value: 1})\n\t}\n\n\t// read from cache \n\titemFromCache, ok := cache.Get(1)\n\tif ok {\n\t\tfmt.Println(\"value is:\", itemFromCache.Value)\n\t}\n}\n```\n\n#### Execute GC manually\n\nIf you need more control over destroying expired key, you can run GC manually when you see fit \n```go\ncache.GCRun()\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkelcik%2Fmemory-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmkelcik%2Fmemory-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkelcik%2Fmemory-cache/lists"}