v2 – git.sr.ht/~xn/cache/v2 Index | Files | Directories

package cache

import "git.sr.ht/~xn/cache/v2"

Index

Types

type Cache

type Cache[V any] interface {
	// Get an item from cache
	Get(key string) V
	// Set an item to cache
	Set(key string, value V)
	// Has an item in cache
	Has(key string) bool
	// Remove an item from cache
	Remove(key string)
	// Purge all items from cache
	Purge()
}

Cache interface, used by any cache implementation

func NewKV

func NewKV[V any]() Cache[V]

NewKV creates a Key Value store

func NewLFU

func NewLFU[V any](size int) Cache[V]

NewLFU creates new Least Frequently Used cache

func NewLRU

func NewLRU[V any](size int) Cache[V]

NewLRU creates new Least Recently Used cache

func NewNull

func NewNull[V any]() Cache[V]

NewNull creates an empty cache client, usable for testing

func NewTLRU

func NewTLRU[V any](size int, ttl time.Duration, stale bool) Cache[V]

NewTLRU cerates new Time aware Least Recently Used cache Arguments: size - max amount if items in cache ttl - cached item expiration duration stale - if true, stale cached item will be returned instead of nil, but only once

Source Files

cache.go

Directories

PathSynopsis
kv
lfu
lru
null
tlru
utils
Version
v2.1.0 (latest)
Published
Aug 29, 2022
Platform
linux/amd64
Imports
6 packages
Last checked
11 hours ago

Tools for package owners.