ttl_map

package module
v1.1.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 27, 2021 License: GPL-3.0 Imports: 8 Imported by: 3

README

Golang in-memory key-value storage with time-to-life

Create new map

import ttl_map "github.com/leprosus/golang-ttl-map"

heap := ttl_map.New()
heap.Path("/path/to/auto-save-file.tsv")

Set/Get

heap.Set("key", "value", 60)

value := heap.Get("key")

Save/Restore

heap.Save()

heap.Restore()

Save/Restore complex data structure

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Data added in v1.1.5

type Data struct {
	Key       string
	Value     interface{}
	Timestamp int64
}

type Heap

type Heap struct {
	// contains filtered or unexported fields
}

func New

func New() *Heap

func (*Heap) Del

func (h *Heap) Del(key string)

func (*Heap) Error

func (h *Heap) Error(fn func(err error))

func (*Heap) Get

func (h *Heap) Get(key string) (val interface{}, ok bool)

func (*Heap) Path added in v1.1.5

func (h *Heap) Path(filePath string)

func (*Heap) Range added in v1.0.2

func (h *Heap) Range(fn func(key string, value interface{}, ttl int64))

func (*Heap) Restore

func (h *Heap) Restore() (err error)

func (*Heap) Save

func (h *Heap) Save() (err error)

func (*Heap) Set

func (h *Heap) Set(key string, value interface{}, ttl int64)

func (*Heap) Support added in v1.1.5

func (h *Heap) Support(kind interface{})

func (*Heap) Wait added in v1.1.5

func (h *Heap) Wait()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL