cache

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2024 License: Apache-2.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 manages the caching of items based on keys with expiration time for cached items.

func NewCache

func NewCache[K comparable, V any](expiration time.Duration) *Cache[K, V]

NewCache creates a new Cache instance with a specified expiration time.

func (*Cache[K, V]) Get

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

Get retrieves an item from the cache based on the provided key. It returns the data and a boolean indicating if the data exists and hasn't expired.

func (*Cache[K, V]) Set

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

Set adds or updates an item in the cache with the provided key and data.

type CacheItem

type CacheItem[V any] struct {
	Data       V
	ExpiryTime time.Time
}

CacheItem represents an item stored in the cache along with its expiration time.

Jump to

Keyboard shortcuts

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