ttlmap

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

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

Go to latest
Published: Jun 19, 2017 License: Apache-2.0 Imports: 6 Imported by: 106

README

This repo is deprecated, Renamed to TTLMap and moved to http://github.com/mailgun/holster

Build Status

TtlMap

Redis-like Map with expiry times and maximum capacity


import "github.com/mailgun/ttlmap"

mh, _ := ttlmap.NewMap(20)
mh.Set("key1", "value", 20)
valI, exists := mh.Get("key2")
if exists {
   val := valI.(string)
}

The ttlmap is not thread safe by default. You can either create a thread safe instance with ttlmap.NewConcurrent that is effectively using sync.RWLock, or implement locking in you application. Beware though that at the application level sync.RWLock cannot be used, because ttlmap.Get can occasionally modifies the internal data structure.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Callback

type Callback func(key string, el interface{})

type TtlMap

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

func NewConcurrent

func NewConcurrent(capacity int, opts ...TtlMapOption) (*TtlMap, error)

func NewMap

func NewMap(capacity int, opts ...TtlMapOption) (*TtlMap, error)

func NewMapWithProvider

func NewMapWithProvider(capacity int, timeProvider timetools.TimeProvider) (*TtlMap, error)

func (*TtlMap) Get

func (m *TtlMap) Get(key string) (interface{}, bool)

func (*TtlMap) GetInt

func (m *TtlMap) GetInt(key string) (int, bool, error)

func (*TtlMap) Increment

func (m *TtlMap) Increment(key string, value int, ttlSeconds int) (int, error)

func (*TtlMap) Len

func (m *TtlMap) Len() int

func (*TtlMap) Set

func (m *TtlMap) Set(key string, value interface{}, ttlSeconds int) error

type TtlMapOption

type TtlMapOption func(m *TtlMap) error

func CallOnExpire

func CallOnExpire(cb Callback) TtlMapOption

CallOnExpire will call this callback on expiration of elements

func Clock

Clock sets the time provider clock, handy for testing

Jump to

Keyboard shortcuts

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