cache

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2025 License: AGPL-3.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

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

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

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

func NewConversationSeqContextCache

func NewConversationSeqContextCache() *ConversationSeqContextCache

func (ConversationSeqContextCache) Delete

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

func (ConversationSeqContextCache) DeleteByViewType

func (c ConversationSeqContextCache) DeleteByViewType(viewType int)

func (ConversationSeqContextCache) Load

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

func (ConversationSeqContextCache) Store

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

func (ConversationSeqContextCache) StoreWithFunc

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

type UserCache

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

func NewUserCache

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

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

func (*UserCache[K, V]) Fetch

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