https://github.com/leprosus/golang-ttl-map
In-memory key-value storage with file snapshots
https://github.com/leprosus/golang-ttl-map
golang map storage ttl ttl-cache
Last synced: 3 months ago
JSON representation
In-memory key-value storage with file snapshots
- Host: GitHub
- URL: https://github.com/leprosus/golang-ttl-map
- Owner: leprosus
- License: gpl-3.0
- Created: 2017-04-19T11:00:27.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2021-04-27T13:27:36.000Z (about 5 years ago)
- Last Synced: 2025-08-09T21:37:44.312Z (10 months ago)
- Topics: golang, map, storage, ttl, ttl-cache
- Language: Go
- Size: 41 KB
- Stars: 7
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- License: License.md
Awesome Lists containing this project
README
# Golang in-memory key-value storage with time-to-life
## Create new map
```go
import ttl_map "github.com/leprosus/golang-ttl-map"
heap := ttl_map.New()
heap.Path("/path/to/auto-save-file.tsv")
```
## Set/Get
```go
heap.Set("key", "value", 60)
value := heap.Get("key")
```
## Save/Restore
```go
heap.Save()
heap.Restore()
```
## Save/Restore complex data structure
```go
var m = map[string]string{}
m["key"] = "value"
heap.Set("obj", m, 60)
heap.Support(map[string]string)
heap.Save()
heap.Restore()
```
## List all methods
* New() - creates new map
* Path(filePath) - sets file path to save/autosave/restore
* Set(key, value, ttl) - adds value by key with ttl in seconds
* Get(key) - returns value or empty string
* Del(key) - deletes value by key
* Range(fn func(key string, value string, ttl int64)) - iterates all actual data
* Support(struct) - registers new structure support (the method is important in a case with complex structure or map)
* Save() - saves map in tsv file
* Restore() - restores map from tsv file