cache

package
v0.0.0-...-e2712e4 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MIN_CACHE_LIFESPAN     = 10 * time.Second
	DEFAULT_CACHE_LIFESPAN = 60 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheTable

type CacheTable struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewCacheTable

func NewCacheTable() *CacheTable

func (*CacheTable) Add

func (table *CacheTable) Add(key string, lifeSpan time.Duration, data any) *CachedItem

Add a CachedItem to the CacheTable without any specific loader

func (*CacheTable) Clear

func (table *CacheTable) Clear()

Remove all CachedItems

func (*CacheTable) Delete

func (table *CacheTable) Delete(key string) (*CachedItem, error)

Remove a specific CachedItem

func (*CacheTable) Fetch

func (table *CacheTable) Fetch(key string, f func() (any, error)) (any, error)

Get a CachedItem saved data or fetch it with the given func

func (*CacheTable) Value

func (table *CacheTable) Value(key string, args ...any) (any, error)

Get a CachedItem saved data or fetch it with its dataloader

type CachedItem

type CachedItem struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewCachedItem

func NewCachedItem(key string, lifeSpan time.Duration, data any, loader func(...any) (any, error)) *CachedItem

func (*CachedItem) Fetch

func (item *CachedItem) Fetch(f func() (any, error)) (any, error)

Get the item saved data or fetch it with the given func

func (*CachedItem) SetData

func (item *CachedItem) SetData(data any)

Unused for now: Manually set a cached item data.

func (*CachedItem) SetDataLoader

func (item *CachedItem) SetDataLoader(f func(...any) (any, error))

Unused for now: Define a data loader for the item

func (*CachedItem) Stop

func (item *CachedItem) Stop()

Thread safe stop the item cleanup Timer

func (*CachedItem) Value

func (item *CachedItem) Value(args ...any) (any, error)

Get the item saved data or fetch it with its dataloader

type ErrNotFound

type ErrNotFound string

func (ErrNotFound) Error

func (e ErrNotFound) Error() string

Jump to

Keyboard shortcuts

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