QuangTung97 / memtable

In-memory cache with 'leasing' mechanism

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

License:MIT License


Languages

Language:Go 99.1%Language:Makefile 0.9%