nixcache

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2022 License: MIT Imports: 5 Imported by: 0

README

NixCache

A fast thread-safe inmemory cache for Go

CI GoDoc Go Report

Features

  • Fast - Using skip list as a data structure.
  • Thread-safe - Use sync.RWMutex to prevent data inconsistency in multithreaded operations.
  • Use LRU Elimination Algorithm.
  • Simple API

Usage example

cache := nixcache.New()
cache.Set("name", "Mike")
value, ok := cache.Get("name")
fmt.Println(ok)
fmt.Println(value.(string))
cache.Delete("name")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	Max uint
	// contains filtered or unexported fields
}

func New

func New() *Cache

Create a cache.

func (*Cache) Delete

func (c *Cache) Delete(key string)

Delete data from the cache.

func (*Cache) Export added in v0.3.0

func (c *Cache) Export(w io.Writer) error

Export data to io.Writer.

func (*Cache) Get

func (c *Cache) Get(key string) (any, bool)

Get data from the cache.

func (*Cache) Len

func (c *Cache) Len() int

Get the cache length.

func (*Cache) Open added in v0.3.0

func (c *Cache) Open(r io.Reader) error

Load data from io.Reader.

func (*Cache) Set

func (c *Cache) Set(key string, value any)

Set data to the cache.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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