memory

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ByteCache

type ByteCache = Cache[[]byte]

func NewByteCache

func NewByteCache() *ByteCache

type Cache

type Cache[T any] struct {
	// contains filtered or unexported fields
}

func NewMemoryCache

func NewMemoryCache[T any]() *Cache[T]

func NewMemoryCacheWithCost

func NewMemoryCacheWithCost[T any](cost func(T) int64) *Cache[T]

func NewMemoryCacheWithRistretto

func NewMemoryCacheWithRistretto[T any](cache *ristretto.Cache[string, T], calculateCost, allowAsyncWrites bool) *Cache[T]

func (*Cache[T]) Close

func (m *Cache[T]) Close() error

func (*Cache[T]) Del

func (m *Cache[T]) Del(ctx context.Context, key string) error

func (*Cache[T]) DelAll

func (m *Cache[T]) DelAll(ctx context.Context) error

func (*Cache[T]) Exists

func (m *Cache[T]) Exists(ctx context.Context, key string) (bool, error)

func (*Cache[T]) Get

func (m *Cache[T]) Get(ctx context.Context, key string) (T, bool, error)

func (*Cache[T]) MultiDel

func (m *Cache[T]) MultiDel(ctx context.Context, keys []string) error

func (*Cache[T]) MultiGet

func (m *Cache[T]) MultiGet(ctx context.Context, keys []string) (map[string]T, error)

func (*Cache[T]) MultiSet

func (m *Cache[T]) MultiSet(ctx context.Context, valMap map[string]T) error

func (*Cache[T]) MultiSetWithTTL

func (m *Cache[T]) MultiSetWithTTL(ctx context.Context, valMap map[string]T, expiration time.Duration) error

func (*Cache[T]) Set

func (m *Cache[T]) Set(ctx context.Context, key string, val T) error

func (*Cache[T]) SetAllowAsyncWrites

func (m *Cache[T]) SetAllowAsyncWrites(allow bool)

SetAllowAsyncWrites In memory.Cache asynchronous writes are disabled by default. If asynchronous writes are enabled, the cache will not block the Set method But it will not guarantee that the value is written to the cache immediately.

func (*Cache[T]) SetWithTTL

func (m *Cache[T]) SetWithTTL(ctx context.Context, key string, val T, expiration time.Duration) error

func (*Cache[T]) UpdateMaxCost

func (m *Cache[T]) UpdateMaxCost(maxItem int64)

UpdateMaxCost In memory.Cache, By default, `calculateCost` is False, so `cost` will be 1. It doesn't care about the size of the item. Calculating cost is too complex and not necessary for most use cases. If you want to limit the number of items in the cache, you use this method to set the maximum number of items. If you want to limit the size of the items in the cache, you can use NewMemoryCacheWithCost

Jump to

Keyboard shortcuts

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