https://github.com/codenoid/minikv
In-memory KV database with expiration (TTL) support, can be dumped and loaded (for non RT persistence).
https://github.com/codenoid/minikv
Last synced: about 1 month ago
JSON representation
In-memory KV database with expiration (TTL) support, can be dumped and loaded (for non RT persistence).
- Host: GitHub
- URL: https://github.com/codenoid/minikv
- Owner: codenoid
- License: mit
- Created: 2021-10-26T15:49:04.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-11-03T03:38:06.000Z (over 4 years ago)
- Last Synced: 2025-04-06T18:50:50.210Z (11 months ago)
- Language: Go
- Size: 10.7 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MiniKV (WIP)

Rewritten from [patrickmn/go-cache](https://github.com/patrickmn/go-cache) with sync.Map and expected behavior.
minikv is an in-memory key:value store/cache that is suitable for applications running on a single machine. Its major advantage is that, being essentially a thread-safe map[string]interface{} with expiration times, it doesn't need to serialize or transmit its contents over the network.
Any object can be stored, for a given duration or forever, and the cache can be safely used by multiple goroutines.
## Installation
`go get github.com/codenoid/minikv`
## Usage
For detailed API's, [go here](https://pkg.go.dev/github.com/codenoid/minikv)
```go
package main
import (
"fmt"
"github.com/codenoid/minikv"
"time"
)
func main() {
// Auto mark key as expired after 5*time.Minute, purge any expired key every
// 10*time.Minute
kv := minikv.New(5*time.Minute, 10*time.Minute)
// Listen to what has been removed and cleaned up (not expired or .Flush()'ed)
kv.OnEvicted(func(key string, value interface{}) {
fmt.Println(key, "has been evicted")
})
// Set the value of the key "foo" to "bar", with the default expiration time
// which is 5*time.Minute
kv.Set("foo", "bar", cache.DefaultExpiration)
// Get the string associated with the key "foo" from the cache
foo, found := c.Get("foo")
if found {
fmt.Println(foo)
}
}
```