https://github.com/arriqaaq/zizou
In memory sharded cache implementation
https://github.com/arriqaaq/zizou
cache go inmem-cache sharded
Last synced: 11 months ago
JSON representation
In memory sharded cache implementation
- Host: GitHub
- URL: https://github.com/arriqaaq/zizou
- Owner: arriqaaq
- License: mit
- Created: 2018-08-02T14:02:04.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2021-06-26T11:14:54.000Z (almost 5 years ago)
- Last Synced: 2025-04-04T06:33:05.554Z (about 1 year ago)
- Topics: cache, go, inmem-cache, sharded
- Language: Go
- Homepage: https://medium.com/@arriqaaq/latency-need-not-always-require-scaling-your-microservice-a-story-of-an-in-memory-cache-384419174ef3
- Size: 13.7 KB
- Stars: 34
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# zizou
In memory cache implementation with high concurrency
## Features
* Store millions of entries
* High concurrent thread-safe access
* Expiration support
* Shard support to avoid locks on whole db during any concurrent read/writes/deletes
## Example Usage
```go
config:=zizou.Config{
SweepTime:10*time.Minute,
ShardSize: 256,
}
cache,err:=zizou.New(&config)
cache.Set("foo", "bar", 10*time.Second)
item, found := cache.Get("foo")
```
## Performance
```bash
BenchmarkCacheGetExpiring-4 20000000 70.0 ns/op
BenchmarkCacheGetNotExpiring-4 20000000 119 ns/op
BenchmarkCacheGetConcurrentExpiring-4 20000000 59.3 ns/op
BenchmarkCacheGetConcurrentNotExpiring-4 20000000 91.3 ns/op
BenchmarkCacheSetExpiring-4 10000000 172 ns/op
BenchmarkCacheSetNotExpiring-4 10000000 134 ns/op
BenchmarkCacheSetDelete-4 5000000 343 ns/op
```
## TODO
- Store data as a map of string and byte array to avoid lookups on object, which will be copied in memory
- Make a circular shard ring, cache objects in individual shard for better concurrency and to avoid locks on the whole cache map object (LRU implementation)
- Use eviction policies of key using a list object, evict those at front
- Implement operations using cmdable interface as done in go-redis(design pattern)
- Check how GC can be avoided
Zizou Image source: https://www.pinterest.ca/pin/436075176391410672/?lp=true