ttlru

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DataWithSignal added in v0.0.7

type DataWithSignal[T any] struct {
	Data   T
	Signal map[string]struct{}
}

type DistributedTTLru added in v0.0.7

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

func NewDistributedTTLru added in v0.0.7

func NewDistributedTTLru[T any](size int, scope string, redis *redis.Client) *DistributedTTLru[T]

NewDistributedTTLru 创建一个可以被分布式清理的 TTLru size: 做多缓存多少个条目 scope: redis scope redis: redis 客户端 一定要记得调用 Start,否则数据不会被清理。

func (*DistributedTTLru[T]) Get added in v0.0.7

func (c *DistributedTTLru[T]) Get(key string) (t T, exist bool)

func (*DistributedTTLru[T]) Set added in v0.0.7

func (c *DistributedTTLru[T]) Set(key string, v T, ttl time.Duration, signals []string)

Set 当 signals 改变时缓存也会被清空。

func (*DistributedTTLru[T]) Size added in v0.0.7

func (c *DistributedTTLru[T]) Size() (curr, max int)

Size 返回 lru 大小

func (*DistributedTTLru[T]) Start added in v0.0.7

func (c *DistributedTTLru[T]) Start(ctx context.Context) (err error)

Start 开始监听清理事件,一定记得 Start,否则数据不会被清理。

func (*DistributedTTLru[T]) UpdateSignal added in v0.0.7

func (c *DistributedTTLru[T]) UpdateSignal(signals ...string) error

UpdateSignal 发送清空信号,清空包含 signal 的数据

type TTLru

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

func NewTTLru

func NewTTLru[T any](size int) *TTLru[T]

func (*TTLru[T]) Delete added in v0.0.7

func (c *TTLru[T]) Delete(key string)

func (*TTLru[T]) Get

func (c *TTLru[T]) Get(key string) (t T, exist bool)

func (*TTLru[T]) Keys added in v0.0.7

func (c *TTLru[T]) Keys() []string

func (*TTLru[T]) Set

func (c *TTLru[T]) Set(key string, v T, ttl time.Duration)

func (*TTLru[T]) Size added in v0.0.7

func (c *TTLru[T]) Size() (curr, max int)

Jump to

Keyboard shortcuts

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