Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/quangtung97/memtable
In-memory cache with 'leasing' mechanism
https://github.com/quangtung97/memtable
cache lease
Last synced: 1 day 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 (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-09-21T04:28:33.000Z (about 3 years ago)
- Last Synced: 2024-06-21T01:59:55.970Z (5 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
[![Go Report Card](https://goreportcard.com/badge/github.com/quangtung97/memtable)](https://goreportcard.com/report/github.com/quangtung97/memtable)
[![Coverage Status](https://coveralls.io/repos/github/QuangTung97/memtable/badge.svg?branch=master)](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