cache

package
v0.1.16-alpha Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.New("resource not found in cache")
)

Functions

This section is empty.

Types

type Default

type Default struct {
	// contains filtered or unexported fields
}

func (*Default) Channels

func (d *Default) Channels() Map[ID, Channel]

func (*Default) Guilds

func (d *Default) Guilds() Map[ID, Guild]

func (*Default) Members

func (d *Default) Members() SubMap[ID, Map[ID, Member]]

func (*Default) Messages

func (d *Default) Messages() SubMap[ID, Map[ID, Message]]

func (*Default) Presences

func (d *Default) Presences() SubMap[ID, Map[ID, Presence]]

func (*Default) ScheduledEvents

func (d *Default) ScheduledEvents() SubMap[ID, Map[ID, ScheduledEvent]]

func (*Default) Users

func (d *Default) Users() Map[ID, User]

func (*Default) VoiceStates

func (d *Default) VoiceStates() SubMap[ID, Map[ID, VoiceState]]

type DefaultConfig

type DefaultConfig struct {
	Users           uint
	Guilds          uint
	Channels        uint
	Messages        uint
	PrivateChannels uint
	Presences       uint
	Members         uint
	MessageLimit    int
}

DefaultConfig is used to set up Default implementation of Store.

type Map

type Map[K comparable, V any] interface {
	Get(key K) (V, error)
	Set(key K, obj V) error
	Delete(key K) error
	// Has checks if specific key exists. Default implementation will return ErrNotFound error if key does not exist.
	Has(key K) error
	// Size
	//
	// It will not return an error in Default implementation.
	Size() (int, error)
	Each(fn MapLambda[V]) error
	Search(fn MapLambda[V]) ([]V, error)
	Clear() error
}

func NewLimitedMap

func NewLimitedMap[K comparable, V any](limit int, preAllocated uint) Map[K, V]

func NewMap

func NewMap[K comparable, V any](preAllocation uint) Map[K, V]

type MapLambda

type MapLambda[T any] func(T) bool

type Store

type Store interface {
	Users() Map[ID, User]
	Guilds() Map[ID, Guild]
	Messages() SubMap[ID, Map[ID, Message]]
	Channels() Map[ID, Channel]
	Presences() SubMap[ID, Map[ID, Presence]]
	Members() SubMap[ID, Map[ID, Member]]
	ScheduledEvents() SubMap[ID, Map[ID, ScheduledEvent]]
	VoiceStates() SubMap[ID, Map[ID, VoiceState]]
}

func NewDefault

func NewDefault(cfg *DefaultConfig) Store

type SubMap

type SubMap[K comparable, V any] interface {
	Get(key K) V
	Delete(key K) error
	Size() (int, error)
	Each(fn MapLambda[V]) error
	Search(fn MapLambda[V]) ([]V, error)
	Clear() error
}

func NewSubMap

func NewSubMap[K comparable, V any](fn SubMapGen[V]) SubMap[K, V]

type SubMapGen

type SubMapGen[T any] func() T

Jump to

Keyboard shortcuts

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