Replace Go's built-in map in any service that handles concurrent reads and writes from multiple goroutines
Build a high-throughput in-memory cache where many requests update the same data store simultaneously
Use as a better alternative to sync.Map when your app constantly updates and removes entries rather than just adding new ones
When a program runs multiple tasks at the same time (called concurrency), those tasks sometimes try to read from and write to the same data structure simultaneously. Go's built-in map type, which is a basic key-value store, is not safe for this kind of simultaneous access. If two tasks try to modify it at the same time, the program can crash or produce wrong results. This repository provides a replacement map that is safe for concurrent use. It achieves good performance by splitting the data across multiple internal shards, so different tasks can often work on different shards at the same time without waiting on each other. This reduces the time tasks spend blocking, compared to a single lock that would stop all activity. Go's standard library added its own concurrent map type called sync.Map in version 1.9, but that version is designed mainly for scenarios where you mostly add new keys and rarely update existing ones. If your program behaves more like a small in-memory database, constantly updating and removing entries, this library is a better fit. The API is straightforward and closely mirrors what Go developers already know from using regular maps. You create a new map, call Set to store a value, Get to retrieve it, and Remove to delete it. The package is imported under the name cmap, and you install it with the standard Go toolchain command. The project is MIT-licensed and accepts contributions. The maintainers ask that contributors open an issue first to describe the change, include tests with any new code, and keep the library as simple and close to the native map behavior as possible.
← orcaman on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.