# README
Library for Consistent Cache
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
# Functions
New ...
WithLeaseListSize configures the number of entries in a lease list.
WithLeaseTimeout for duration of lease timeout, in second.
WithNumBuckets configures number of lease buckets.
# Constants
GetStatusFound for normal cache hit case.
GetStatusLeaseGranted when cache miss and lease is granted.
GetStatusLeaseRejected when cache miss and lease is not granted.