ttlcache

package
v4.5.5 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2024 License: MIT Imports: 3 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache is a synchronised map of items that auto-expire once stale

func NewCache

func NewCache(duration time.Duration) *Cache

NewCache is a helper to create instance of the Cache struct

func (*Cache) AddToSlice

func (cache *Cache) AddToSlice(key string, data interface{})

AddToSlice implements a super dirty slice cache method

func (*Cache) Count

func (cache *Cache) Count() int

Count returns the number of items in the cache (helpful for tracking memory leaks)

func (*Cache) Delete

func (cache *Cache) Delete(key string)

Delete is a thread-safe way to delete items from the map

func (*Cache) Dump

func (cache *Cache) Dump()

Dump is a thread-safe way to fully clear the cache

func (*Cache) Get

func (cache *Cache) Get(key string) (data interface{}, found bool)

Get is a thread-safe way to lookup items Every lookup, also touches the item, hence extending it's life

func (*Cache) GetSimple added in v4.4.5

func (cache *Cache) GetSimple(key string) (data interface{}, found bool)

GetSimple is a thread-safe way to lookup items GetSimple works like Get but does not touch the item, hence not extending it's life

func (*Cache) Set

func (cache *Cache) Set(key string, data interface{})

Set is a thread-safe way to add new items to the map

type Item

type Item struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Item represents a record in the cache map

Jump to

Keyboard shortcuts

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