cache

package
v1.6.8 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2022 License: MIT Imports: 3 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[K comparable, V any] interface {
	// Get - get data(Value) for Key (return Value if key doesn't expire)
	Get(K) (V, bool)

	// Set - set data(Value) for Key (without TTL, not expired)
	Set(K, V)

	// SetWithTTL - set data(Value) for Key (with TTL or when expired)
	SetWithTTL(K, V, TTL)

	// SetTTL - set TTL for Key
	SetTTL(K, TTL)

	// TryGetOrInvokeLambda - try Get(Key) if not found, exec Lambda and if success store Value by Set func
	TryGetOrInvokeLambda(K, lambda[K, V]) (V, error)

	// Delete - delete Key
	Delete(K)

	// CleanAll - delete all data in storage (all Key)
	CleanAll()
}

Cache - interface of cache.

func New

func New[K comparable, V any](config Config) (Cache[K, V], error)

New "Constructor" of Cache

type Config

type Config struct {
	DefaultTTL string `yaml:"default_ttl"`

	CustomCacheConfig map[string]any `yaml:"customCacheConfig"`
}

Config - for cache.

type TTL

type TTL = struct {
	TTL      time.Duration // PREFER(more important) THAN ExpireAt
	ExpireAt time.Time
}

TTL - struct describe TTL use cases for cache.

Jump to

Keyboard shortcuts

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