expiremap

package module
v0.0.0-...-00934ac Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2020 License: BSD-3-Clause Imports: 4 Imported by: 0

README

go.expiremap

Package expiremap is a simple thread-safe cache like sync.Map. Value in this map will automatically be deleted after expiration time.

This package acts like go-cache(github.com/patrickmn/go-cache), but much faster. The limitations are: expiration could not changed once the map is established, and the actual expiration time for each value may have an error of up to one second. These are the cost of increased effenciency.

Documentation

Overview

Package expiremap is a simple thread-safe cache like sync.Map. Value in this map will automatically be deleted after expiration time.

This package acts like go-cache(github.com/patrickmn/go-cache), but much faster. The limitations are: expiration could not changed once the map is established, and the actual expiration time for each value may have an error of up to one second. These are the cost of increased effenciency.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Map

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

Map is the main instance of this package.

func New

func New(expiration time.Duration) *Map

New initialize and return an expiremap instance with given expiration for each element.

The exact expiration time for each element may have up to one second longer because the map checks expiration every one second.

func (*Map) Expiration

func (m *Map) Expiration() time.Duration

Expiration returns the expiration time for each values in this map.

func (*Map) Load

func (m *Map) Load(key interface{}) (value interface{}, ok bool)

Load returns the value stored in the map for a key, or nil if no value is present. The ok result indicates whether key exists in the map.

func (*Map) Store

func (m *Map) Store(key, value interface{})

Store stores an value with default expiration.

Jump to

Keyboard shortcuts

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