yache

package module
v0.0.0-...-d3040e3 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2022 License: GPL-3.0 Imports: 1 Imported by: 0

README

yache

A very simple library to store data in a Go variable for a limited number of seconds.

How to use

go get github.com/alexcoder04/yache
import (
    "time"

    "github.com/alexcoder04/yache"
)

func main() {
    // create a store to save data only for 5 seconds
    store := yache.NewStore(5)

    // save data
    store.Set("test", "Hello World")

    // get data
    fmt.Println(store.Get("test")) // prints "Hello World"

    // wait
    time.Sleep(7 * time.Second)

    // get data again
    fmt.Println(store.Get("test")) // prints nil
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Item

type Item struct {
	Expires int64
	Value   any
}

type Store

type Store struct {
	Timeout          int64
	Autoflush        bool
	AutoflushStarted bool
	Data             map[string]Item
}

func NewStore

func NewStore(timeout int64, autoflush bool) Store

func (*Store) Flush

func (s *Store) Flush()

func (*Store) Get

func (s *Store) Get(key string) any

func (*Store) Set

func (s *Store) Set(key string, val any)

Jump to

Keyboard shortcuts

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