~blainsmith/shardcache

Simple in-memory shard cache to reduce write locks for a large number of keys.
7a20aab6 — Blain Smith 18 days ago
read lock just the shards
9da8c653 — Blain Smith 18 days ago
oversight copy/paste with read lock
1a649ffb — Blain Smith 18 days ago
test delete

refs

main
browse  log 

clone

read-only
https://git.sr.ht/~blainsmith/shardcache
read/write
git@git.sr.ht:~blainsmith/shardcache

You can also use your local clone with git send-email.

#Shard Cache

Warning: Do not use this since it is still evolving.

Shard Cache is meant to remove having to lock the entire cache to write a single item to it. Instead the cache is set up into shared based on the key so there can be an unlimited amount of read locks and a write lock per shard. This lets reads be unblocked for all N-1 shards while a single item in a shard is being written.

// set up a cache with 64 shards, Shards MUST be a power of 2
sc := shardcache.New(64)

sc.Set(512, "my-512-value")
sc.Set(101, "my-101-value")

val, ok := sc.Get(101).(string)
if !ok {
    // derp
}

fmt.Println(val) // prints "my-101-value"