cache

package
v0.3.1-beta Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: GPL-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[TKey CacheKeyConstraint, TValue CacheValueConstraint] interface {
	// Check if the cache contains a value associated to a given key
	HasKey(k TKey) bool

	// Retrieve a value associated to a given key
	GetValue(k TKey) (TValue, error)

	// Add or overwrite a cached value associated to a given key. The return value indicates if the operation was successful
	SetValue(k TKey, v TValue) bool
}

Utility used to cache values using key-value mapping

func CreateInMemoryCache

func CreateInMemoryCache[TKey CacheKeyConstraint, TValue CacheValueConstraint](maxSize int) (Cache[TKey, TValue], error)

Create a new instance of a in-memory cache with a given cache size. If the size is set to 0 the cache will have not size limit

type CacheKeyConstraint

type CacheKeyConstraint interface {
	comparable
}

type CacheValueConstraint

type CacheValueConstraint interface {
	any
}

Jump to

Keyboard shortcuts

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