cache

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2025 License: Apache-2.0 Imports: 2 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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