cache

package
v3.8.3 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ViewHistory = iota
	ViewSearch
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache[K comparable, V any] struct {
	// contains filtered or unexported fields
}

Cache is a Generic sync.Map structure.

func NewCache

func NewCache[K comparable, V any]() *Cache[K, V]

func (*Cache[K, V]) Delete

func (c *Cache[K, V]) Delete(key K)

Delete deletes the value for a key.

func (*Cache[K, V]) DeleteAll

func (c *Cache[K, V]) DeleteAll()

DeleteAll deletes all values.

func (*Cache[K, V]) DeleteCon added in v3.8.3

func (c *Cache[K, V]) DeleteCon(condition func(key K, value V) bool)

DeleteCon deletes the value for a key only if the provided condition function returns true.

func (*Cache[K, V]) Load

func (c *Cache[K, V]) Load(key K) (value V, ok bool)

Load returns the value stored in the map for a key, or nil if no value is present.

func (*Cache[K, V]) LoadOrStore

func (c *Cache[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool)

LoadOrStore returns the existing value for the key if present.

func (*Cache[K, V]) RangeAll

func (c *Cache[K, V]) RangeAll() (values []V)

RangeAll returns all values in the map.

func (*Cache[K, V]) RangeCon

func (c *Cache[K, V]) RangeCon(f func(key K, value V) bool) (values []V)

RangeCon returns values in the map that satisfy condition f.

func (*Cache[K, V]) Store

func (c *Cache[K, V]) Store(key K, value V)

Store sets the value for a key.

func (*Cache[K, V]) StoreAll

func (c *Cache[K, V]) StoreAll(f func(value V) K, values []V)

StoreAll sets all value by f's key.

func (*Cache[K, V]) StoreWithFunc added in v3.8.3

func (c *Cache[K, V]) StoreWithFunc(key K, value V, condition func(key K, value V) bool)

StoreWithFunc stores the value for a key only if the provided condition function returns true.

type ConversationSeqContextCache added in v3.8.3

type ConversationSeqContextCache struct {
	*Cache[string, int64]
}

func NewConversationSeqContextCache added in v3.8.3

func NewConversationSeqContextCache() *ConversationSeqContextCache

func (ConversationSeqContextCache) Delete added in v3.8.3

func (c ConversationSeqContextCache) Delete(conversationID string, viewType int)

func (ConversationSeqContextCache) DeleteByViewType added in v3.8.3

func (c ConversationSeqContextCache) DeleteByViewType(viewType int)

func (ConversationSeqContextCache) Load added in v3.8.3

func (c ConversationSeqContextCache) Load(conversationID string, viewType int) (int64, bool)

func (ConversationSeqContextCache) Store added in v3.8.3

func (c ConversationSeqContextCache) Store(conversationID string, viewType int, thisEndSeq int64)

func (ConversationSeqContextCache) StoreWithFunc added in v3.8.3

func (c ConversationSeqContextCache) StoreWithFunc(conversationID string, viewType int, thisEndSeq int64, fn func(key string, value int64) bool)

type UserCache added in v3.8.3

type UserCache[K comparable, V any] struct {
	*Cache[K, V]
	// contains filtered or unexported fields
}

func NewUserCache added in v3.8.3

func NewUserCache[K comparable, V any](
	getKeyFunc func(value V) K,
	batchDBFunc func(ctx context.Context, keys []K) ([]V, error),
	singleDBFunc func(ctx context.Context, keys K) (V, error),
	queryFunc func(ctx context.Context, keys []K) ([]V, error),
) *UserCache[K, V]

func (*UserCache[K, V]) BatchFetch added in v3.8.3

func (m *UserCache[K, V]) BatchFetch(ctx context.Context, keys []K) (map[K]V, error)

func (*UserCache[K, V]) Fetch added in v3.8.3

func (m *UserCache[K, V]) Fetch(ctx context.Context, key K) (V, error)

Jump to

Keyboard shortcuts

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