v2_1

package
v0.0.0-...-18f1ea7 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2023 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 LocalCache

type LocalCache struct {
	// contains filtered or unexported fields
}

func NewLocalCache

func NewLocalCache(interval time.Duration, opts ...LocalCacheOption) *LocalCache

func (*LocalCache) Close

func (c *LocalCache) Close() error

func (*LocalCache) Delete

func (c *LocalCache) Delete(ctx context.Context, key string) error

func (*LocalCache) Get

func (c *LocalCache) Get(ctx context.Context, k string) (any, error)

Get 的时候,粗暴的做法是直接加写锁,但是也可以考虑用 double-check 写法。 我们使用的就是这个方案。 前面我们提到不能使用 sync.Map,从这里也可以看出来。

func (*LocalCache) Set

func (c *LocalCache) Set(ctx context.Context, k string, v any, expiration time.Duration) error

type LocalCacheOption

type LocalCacheOption func(cache *LocalCache)

func LocalCacheWithEvictedCallback

func LocalCacheWithEvictedCallback(fn func(k string, v any)) LocalCacheOption

Jump to

Keyboard shortcuts

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