cachettl

package
v1.5.0-rc.5 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2023 License: AGPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache[K comparable, V any] struct {
	// contains filtered or unexported fields
}

Cache is a double linked list sorted by expiration time (ascending order) the root (head) node is the node with the lowest expiration time the tail node (end) is the node with the highest expiration time Cleanups are done on Get() calls so if Get() is never invoked then Nodes stay in-memory.

func New

func New[K comparable, V any]() *Cache[K, V]

New returns a new Cache.

func (*Cache[K, V]) Get

func (c *Cache[K, V]) Get(key K) (zero V)

Get returns the value associated with the key or nil otherwise. Additionally, Get() will refresh the TTL and cleanup expired nodes.

func (*Cache[K, V]) Put

func (c *Cache[K, V]) Put(key K, value V, ttl time.Duration)

Put adds or updates an element inside the Cache. The Cache will be sorted with the node with the highest expiration at the tail.

Jump to

Keyboard shortcuts

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