Skip to content

QuangTung97/memtable

Repository files navigation

Library for Consistent Cache

Go Report Card Coverage Status

Based on the freecache library and the 'leasing' mechanism of the paper Scaling Memcache at Facebook.

Usage

cacheSize := 100 * 1024 * 1024 // 100MB
cache := memtable.New(cacheSize)

for {
    key := []byte("some-key")
    result := cache.Get(key)
    if result.Status == memtable.GetStatusLeaseRejected {
    	time.Sleep(100 * time.Millisecond)
    	continue
    }
    
    if result.Status == memtable.GetStatusFound {
    	// cache hit
    	fmt.Println("Got value:", result.Value)
    	return
    }
    
    // cache miss but lease is granted
    // get data from database
    value := []byte("some-value")
    
    affected := cache.Set(key, result.LeaseID, value)
    fmt.Println("Affected:", affected)
    return
}

License

The MIT License

About

In-memory cache with 'leasing' mechanism

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published