{"id":13396801,"url":"https://github.com/coocood/freecache","last_synced_at":"2025-05-15T01:00:33.329Z","repository":{"id":31234380,"uuid":"34795642","full_name":"coocood/freecache","owner":"coocood","description":"A cache library for Go with zero GC overhead.","archived":false,"fork":false,"pushed_at":"2024-04-12T15:10:32.000Z","size":126,"stargazers_count":5200,"open_issues_count":44,"forks_count":392,"subscribers_count":113,"default_branch":"master","last_synced_at":"2025-04-22T20:08:24.190Z","etag":null,"topics":[],"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/coocood.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":"2015-04-29T13:34:31.000Z","updated_at":"2025-04-22T14:50:08.000Z","dependencies_parsed_at":"2024-03-26T04:31:54.205Z","dependency_job_id":"7b5ed2d5-5f45-4eb6-8ece-b7720e31f03c","html_url":"https://github.com/coocood/freecache","commit_stats":{"total_commits":72,"total_committers":33,"mean_commits":"2.1818181818181817","dds":0.6388888888888888,"last_synced_commit":"eadf666f037f5f88b4cc4f4d2c575defaa0c141d"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coocood%2Ffreecache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coocood%2Ffreecache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coocood%2Ffreecache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coocood%2Ffreecache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coocood","download_url":"https://codeload.github.com/coocood/freecache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252882779,"owners_count":21819152,"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":[],"created_at":"2024-07-30T18:01:03.485Z","updated_at":"2025-05-07T12:48:55.356Z","avatar_url":"https://github.com/coocood.png","language":"Go","readme":"# FreeCache - A cache library for Go with zero GC overhead and high concurrent performance.\n\nLong lived objects in memory introduce expensive GC overhead, With FreeCache, you can cache unlimited number of objects in memory \nwithout increased latency and degraded throughput. \n\n[![Build Status](https://github.com/coocood/freecache/workflows/Test/badge.svg)](https://github.com/coocood/freecache/actions/workflows/test.yml)\n[![GoCover](http://github.com/coocood/freecache/wiki/coverage.svg)](https://raw.githack.com/wiki/coocood/freecache/coverage.html)\n[![GoDoc](https://godoc.org/github.com/coocood/freecache?status.svg)](https://godoc.org/github.com/coocood/freecache)\n\n## Features\n\n* Store hundreds of millions of entries\n* Zero GC overhead\n* High concurrent thread-safe access\n* Pure Go implementation\n* Expiration support\n* Nearly LRU algorithm\n* Strictly limited memory usage\n* Come with a toy server that supports a few basic Redis commands with pipeline\n* Iterator support\n\n## Performance\n\nHere is the benchmark result compares to built-in map, `Set` performance is about 2x faster than built-in map, `Get` performance is about 1/2x slower than built-in map. Since it is single threaded benchmark, in multi-threaded environment, \nFreeCache should be many times faster than single lock protected built-in map.\n\n    BenchmarkCacheSet        3000000               446 ns/op\n    BenchmarkMapSet          2000000               861 ns/op\n    BenchmarkCacheGet        3000000               517 ns/op\n    BenchmarkMapGet         10000000               212 ns/op\n\n## Example Usage\n\n```go\n// In bytes, where 1024 * 1024 represents a single Megabyte, and 100 * 1024*1024 represents 100 Megabytes.\ncacheSize := 100 * 1024 * 1024\ncache := freecache.NewCache(cacheSize)\ndebug.SetGCPercent(20)\nkey := []byte(\"abc\")\nval := []byte(\"def\")\nexpire := 60 // expire in 60 seconds\ncache.Set(key, val, expire)\ngot, err := cache.Get(key)\nif err != nil {\n    fmt.Println(err)\n} else {\n    fmt.Printf(\"%s\\n\", got)\n}\naffected := cache.Del(key)\nfmt.Println(\"deleted key \", affected)\nfmt.Println(\"entry count \", cache.EntryCount())\n```\n\n## Notice\n\n* Memory is preallocated.\n* If you allocate large amount of memory, you may need to set `debug.SetGCPercent()`\nto a much lower percentage to get a normal GC frequency.\n* If you set a key to be expired in X seconds, e.g. using `cache.Set(key, val, X)`, \nthe effective cache duration will be within this range: `(X-1, X] seconds`.\nThis is because that sub-second time at the moment will be ignored when calculating the\nthe expiration: for example, if the current time is 8:15::01.800 (800 milliseconds passed\nsince 8:15::01), the actual duration will be `X-800ms`.\n\n## How it is done\n\nFreeCache avoids GC overhead by reducing the number of pointers.\nNo matter how many entries stored in it, there are only 512 pointers.\nThe data set is sharded into 256 segments by the hash value of the key.\nEach segment has only two pointers, one is the ring buffer that stores keys and values, \nthe other one is the index slice which used to lookup for an entry.\nEach segment has its own lock, so it supports high concurrent access.\n\n## TODO\n\n* Support dump to file and load from file.\n* Support resize cache size at runtime.\n\n## License\n\nThe MIT License\n","funding_links":[],"categories":["Library","开源类库","Go","Open source library"],"sub_categories":["缓存","Cache"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoocood%2Ffreecache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoocood%2Ffreecache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoocood%2Ffreecache/lists"}