gokv

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2022 License: MIT Imports: 5 Imported by: 0

README

GoKV

GoKV is a key-value storage in the memory, it is simple and fast.

Requirements

Go1.18+

Installation

go get -u github.com/skyline93/gokv

Example

package main

import (
	"github.com/skyline93/gokv"
)

func main(){
	cache := gokv.New(5)
	cache.Put("key1", "value1")
	key2 := cache.PutWithKey("value2")   // auto generate key

	v1 := cache.Get("key1")
	v2 := cache.Get(key2)	
}
package main

import (
	"time"
	
	"github.com/skyline93/gokv"
)

func main(){
	cache := gokv.New(5)
	cache.Put("key1", "value1", 2)        // value expires after 2 second
	key2 := cache.PutWithKey("value2", 5) // value expires after 5 second


	time.Sleep(time.Second * 2)
	v1 := cache.Get("key1")                // v1 is nil

	time.Sleep(time.Second * 3)
	v2 := cache.Get(key2)                  // v2 is nil	
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache added in v0.2.0

type Cache struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func New

func New(len int) *Cache

func (*Cache) Delete added in v0.2.0

func (c *Cache) Delete(key string)

func (*Cache) Get added in v0.2.0

func (c *Cache) Get(key string) interface{}

func (*Cache) Put added in v0.2.0

func (c *Cache) Put(key string, value interface{}, opts ...interface{})

func (*Cache) PutWithKey added in v0.2.0

func (c *Cache) PutWithKey(value interface{}, opts ...interface{}) (key string)

type List added in v0.2.0

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

func (*List) All added in v0.2.0

func (l *List) All()

func (*List) Delete added in v0.2.0

func (l *List) Delete(key interface{})

func (*List) Head added in v0.2.0

func (l *List) Head() (key interface{})

func (*List) Insert added in v0.2.0

func (l *List) Insert(key interface{})

type Node added in v0.2.0

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

type Value

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

func NewValue

func NewValue(v interface{}, ttl int) *Value

func (*Value) IsExpired

func (v *Value) IsExpired() bool

Jump to

Keyboard shortcuts

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