caches

package
v0.0.36 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2025 License: MIT Imports: 8 Imported by: 6

Documentation

Index

Constants

View Source
const (
	StorageTypeMemory = StorageType("memory")
	StorageTypeSQLite = StorageType("sqlite")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config added in v0.0.27

type Config struct {
	StorageType StorageType
	Dir         string
}

type Interface

type Interface[T any] interface {
	// Remember value by key. If key is exists and ttl is not expired then return value without call callback.
	// If key is not exists or ttl is expired then call callback and remember value by key.
	// Error is returned from callback if failed.
	Remember(key string, ttlS uint64, callback func() (T, error)) (T, error)

	// Clear all cache.
	Clear()

	// Forget cache value by key.
	Forget(key string) (T, error)

	// Determine your own logic with function to forget cache by key
	ForgetFn(func(key string) (T, error)) (T, error)

	// Get length of cache.
	Length() uint64

	// Get cache value by key
	Get(key string) (T, error)

	// Get keys that stored on caches
	Keys() []string
}

func Init added in v0.0.27

func Init[T any](cfg Config) (Interface[T], error)

func InitMemory added in v0.0.27

func InitMemory[T any](cfg Config) Interface[T]

func InitSQLite added in v0.0.36

func InitSQLite[T any](cfg Config) Interface[T]

type StorageType added in v0.0.27

type StorageType string

Jump to

Keyboard shortcuts

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