Documentation
¶
Index ¶
- type Cache
- type CacheLayer
- type MultiLevelCache
- func (m *MultiLevelCache[K, V]) Clear(ctx context.Context) error
- func (m *MultiLevelCache[K, V]) Delete(ctx context.Context, key K) error
- func (m *MultiLevelCache[K, V]) Get(ctx context.Context, key K) (V, bool)
- func (m *MultiLevelCache[K, V]) Set(ctx context.Context, key K, value V, ttl time.Duration) error
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 删除缓存
Click to show internal directories.
Click to hide internal directories.