cache

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package cache provides a simple cache.

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 thread safe key/value map where the entries can expire.

func New

func New[K comparable, V any](lifetime time.Duration) *Cache[K, V]

New creates a new cache where the lifetime is the duration of a valid cache entry, after which the entry is considered expired.

func (*Cache[K, V]) Get

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

Get returns a copy of of the value V associated with the key, and the status of that value. A status of true indicates the value can be used. A status of false indicates the value is unusable, being either expired or not in the cache.

func (*Cache[K, V]) Remove

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

Remove deletes value from the cache. If the value isn't present in the cache, this is a no-op.

func (*Cache[K, V]) Set

func (c *Cache[K, V]) Set(key K, value V)

Set will create or update the value associated for the given key.

Jump to

Keyboard shortcuts

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