https://github.com/quangtung97/memtable
In-memory cache with 'leasing' mechanism
https://github.com/quangtung97/memtable
cache lease
Last synced: 3 months ago
JSON representation
In-memory cache with 'leasing' mechanism
- Host: GitHub
- URL: https://github.com/quangtung97/memtable
- Owner: QuangTung97
- License: mit
- Created: 2021-07-07T08:46:13.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-09-21T04:28:33.000Z (over 3 years ago)
- Last Synced: 2025-01-13T15:16:54.585Z (4 months ago)
- Topics: cache, lease
- Language: Go
- Homepage:
- Size: 13.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Library for Consistent Cache
[](https://goreportcard.com/report/github.com/quangtung97/memtable)
[](https://coveralls.io/github/QuangTung97/memtable?branch=master)Based on the [freecache](https://github.com/coocood/freecache) library and the 'leasing' mechanism of the paper
[Scaling Memcache at Facebook](https://www.usenix.org/system/files/conference/nsdi13/nsdi13-final170_update.pdf).## Usage
```go
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