memcache 📚
DHT cache, Built with consitent hashing & LRU/LFU cache
Example
Memcache
package main
import (
"fmt"
"github.com/escalopa/memcache"
)
func main() {
nodes := 1_000
capacity := 1_000_000
mc := memcache.New(nodes, capacity, memcache.NewLRU) // Or use `memcache.NewLFU`
// If no nodes are needed, use:
// mc := meme.NewLRU(capacity)
// Or
// mc := meme.NewLFU(capacity)
var value interface{}
var ok bool
value, ok = mc.Get("foo")
fmt.Println(value, ok)
// Output: <nil> false
mc.Set("foo", "bar", 0)
value, ok = mc.Get("foo")
fmt.Println(value, ok)
// Output: bar true
mc.Delete("foo")
value, ok = mc.Get("foo")
fmt.Println(value, ok)
// Output: <nil> false
mc.Set("foo", "bar", 0)
value, ok = mc.Get("foo")
fmt.Println(value, ok)
// Output: bar true
}
About
DHT
Distributed Hash Table (DHT) is a distributed system that provides a lookup service similar to a hash table. It assigns keys to nodes in the network using a hash function. This allows the nodes to efficiently retrieve the value associated with a given key.
Notice: This project implements DHT on a single node. It is not distributed.
LRU
Least Recently Used (LRU) is a common caching strategy. It defines that the least recently used items are discarded first.
LFU
Least Frequently Used (LFU) is a caching strategy whereby the least frequently used items are discarded first.
References