xfreecache

package
v0.11.3 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Byte Size = 1
	KB        = 1024 * Byte
	MB        = 1024 * KB
	GB        = 1024 * MB
	TB        = 1024 * GB
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Cache         *freecache.Cache `json:"-" toml:"-"`                         // 本地缓存实例【必填】
	Expire        time.Duration    `json:"expire" toml:"expire"`               // 失效时间 【必填】
	DisableMetric bool             `json:"disableMetric" toml:"disableMetric"` // metric上报 false 开启  ture 关闭【选填,默认开启】
	Name          string           `json:"-" toml:"-"`                         // 本地缓存名称,用于日志标识&metric上报【选填】
}

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig 返回默认配置

func StdConfig

func StdConfig(name string) *Config

StdConfig 返回标准配置

type LocalCache

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

func New

func New[K comparable, V any](c *Config) (localCache *LocalCache[K, V])

New 构建本地缓存实例 缓存容量默认256MB 最小512KB 最大8GB

func StdNew

func StdNew[K comparable, V any](name string) (localCache *LocalCache[K, V])

StdNew 构建本地缓存实例 The entry size need less than 1/1024 of cache size

func (*LocalCache) GetAndSetCacheData

func (c *LocalCache) GetAndSetCacheData(key string, id K, fn func() (V, error)) (value V, err error)

GetAndSetCacheData 获取缓存后数据

func (*LocalCache) GetAndSetCacheMap

func (c *LocalCache) GetAndSetCacheMap(key string, ids []K, fn func([]K) (map[K]V, error)) (v map[K]V, err error)

GetAndSetCacheMap 获取缓存后数据 map形式

type Size

type Size int

func ParseSize

func ParseSize(s string) (Size, error)

ParseSize parses a size string. Valid time units are "b" (or "byte"), "kb", "mb", "gb", "tb".

Jump to

Keyboard shortcuts

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