cache

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2025 License: Apache-2.0 Imports: 2 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(ctx context.Context, key K) (V, bool)
	// Set 设置缓存值
	Set(ctx context.Context, key K, value V, ttl time.Duration) error
	// Delete 删除缓存
	Delete(ctx context.Context, key K) error
	// Clear 清空缓存
	Clear(ctx context.Context) error
	// Name 获取缓存名称
	Name() string
}

Cache 定义缓存接口

type CacheLayer

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

CacheLayer 缓存层

func NewCacheLayer

func NewCacheLayer[K comparable, V any](cache Cache[K, V], ttlFactor float64) CacheLayer[K, V]

NewCacheLayer 创建缓存层

type MultiLevelCache

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

MultiLevelCache 多级缓存

func NewMultiLevelCache

func NewMultiLevelCache[K comparable, V any](layers ...CacheLayer[K, V]) *MultiLevelCache[K, V]

NewMultiLevelCache 创建多级缓存

func (*MultiLevelCache[K, V]) Clear

func (m *MultiLevelCache[K, V]) Clear(ctx context.Context) error

Clear 清空缓存

func (*MultiLevelCache[K, V]) Delete

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

Delete 删除缓存

func (*MultiLevelCache[K, V]) Get

func (m *MultiLevelCache[K, V]) Get(ctx context.Context, key K) (V, bool)

Get 获取缓存值

func (*MultiLevelCache[K, V]) Set

func (m *MultiLevelCache[K, V]) Set(ctx context.Context, key K, value V, ttl time.Duration) error

Set 设置缓存值

Jump to

Keyboard shortcuts

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