cache

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

README

framework-cache

Go framework package for cache.

Installation

go get github.com/go-anyway/framework-cache@v1.0.0

Usage

See documentation for usage examples.

License

Apache License 2.0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Enabled           bool               `yaml:"enabled" env:"CACHE_ENABLED" default:"true"`
	DefaultExpiration pkgConfig.Duration `yaml:"default_expiration" env:"CACHE_DEFAULT_EXPIRATION" default:"5m"`
	CleanupInterval   pkgConfig.Duration `yaml:"cleanup_interval" env:"CACHE_CLEANUP_INTERVAL" default:"10m"`
	EnableStats       bool               `yaml:"enable_stats" env:"CACHE_ENABLE_STATS" default:"true"`
}

Config 本地缓存配置结构体(用于从配置文件创建)

func (*Config) ToOptions

func (c *Config) ToOptions() (*Options, error)

ToOptions 转换为 Options

func (*Config) Validate

func (c *Config) Validate() error

Validate 验证本地缓存配置

type LocalCache

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

LocalCache 本地缓存封装

func NewLocalCache

func NewLocalCache(opts *Options) *LocalCache

NewLocalCache 创建新的本地缓存

func (*LocalCache) Clear

func (lc *LocalCache) Clear()

Clear 清空所有缓存

func (*LocalCache) Delete

func (lc *LocalCache) Delete(key string)

Delete 删除值

func (*LocalCache) Get

func (lc *LocalCache) Get(key string) (interface{}, bool)

Get 获取值

func (*LocalCache) GetStats

func (lc *LocalCache) GetStats() *Stats

GetStats 获取统计信息

func (*LocalCache) ItemCount

func (lc *LocalCache) ItemCount() int

ItemCount 获取缓存项数量

func (*LocalCache) Set

func (lc *LocalCache) Set(key string, value interface{}, expiration time.Duration)

Set 设置值

type Options

type Options struct {
	DefaultExpiration time.Duration // 默认过期时间
	CleanupInterval   time.Duration // 清理间隔
	EnableStats       bool          // 是否启用统计
}

Options 本地缓存配置选项(内部使用)

func DefaultOptions

func DefaultOptions() *Options

DefaultOptions 返回默认配置选项

type Stats

type Stats struct {
	Hits       int64
	Misses     int64
	Sets       int64
	Deletes    int64
	Items      int64
	MemorySize int64 // 估算的内存大小(字节)
}

Stats 缓存统计信息

Jump to

Keyboard shortcuts

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