cache

package
v2.6.27 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeMem    = "memory"
	TypeRedis  = "redis"
	TypeFile   = "file"
	MaxTimeOut = 365 * 24 * 3600
)

Variables

This section is empty.

Functions

func DecodeValue

func DecodeValue(value string, rtv interface{}) error

func EncodeValue

func EncodeValue(value interface{}) (string, error)

Types

type CacheItem

type CacheItem struct {
	Key        string
	Value      string
	Expiration int64
	Index      int
	ListEle    *list.Element
}

type FileCache

type FileCache struct {
	Dir string
	// contains filtered or unexported fields
}

func NewFileCache

func NewFileCache() *FileCache

func (*FileCache) Gc

func (c *FileCache) Gc() error

func (*FileCache) Get

func (c *FileCache) Get(key string, value interface{}) error

func (*FileCache) Set

func (c *FileCache) Set(key string, value interface{}, exp int) error

func (*FileCache) SetDir

func (c *FileCache) SetDir(path string)

type Handler

type Handler interface {
	Get(key string, value interface{}) error
	Set(key string, value interface{}, exp int) error
	Gc() error
}

func New

func New(typ string) Handler

type MemoryCache

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

func NewMemoryCache

func NewMemoryCache(maxBytes int64) *MemoryCache

NewMemoryCache creates a new MemoryCache.default maxBytes is 0, means no limit.

func (*MemoryCache) Gc

func (m *MemoryCache) Gc() error

func (*MemoryCache) Get

func (m *MemoryCache) Get(key string, value interface{}) error

func (*MemoryCache) RemoveOldest

func (m *MemoryCache) RemoveOldest()

func (*MemoryCache) Set

func (m *MemoryCache) Set(key string, value interface{}, exp int) error

type PriorityQueue

type PriorityQueue []*CacheItem

func (PriorityQueue) Len

func (pq PriorityQueue) Len() int

func (PriorityQueue) Less

func (pq PriorityQueue) Less(i, j int) bool

func (*PriorityQueue) Pop

func (pq *PriorityQueue) Pop() interface{}

func (*PriorityQueue) Push

func (pq *PriorityQueue) Push(x interface{})

func (PriorityQueue) Swap

func (pq PriorityQueue) Swap(i, j int)

type RedisCache

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

func NewRedis

func NewRedis(conf *redis.Options) *RedisCache

func RedisCacheInit

func RedisCacheInit(conf *redis.Options) *RedisCache

func (*RedisCache) Gc

func (c *RedisCache) Gc() error

func (*RedisCache) Get

func (c *RedisCache) Get(key string, value interface{}) error

func (*RedisCache) Set

func (c *RedisCache) Set(key string, value interface{}, exp int) error

type SimpleCache

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

此处实现了一个简单的缓存,用于测试 SimpleCache is a simple cache implementation

func NewSimpleCache

func NewSimpleCache() *SimpleCache

func (*SimpleCache) Gc

func (s *SimpleCache) Gc() error

func (*SimpleCache) Get

func (s *SimpleCache) Get(key string, value interface{}) error

func (*SimpleCache) Set

func (s *SimpleCache) Set(key string, value interface{}, exp int) error

Jump to

Keyboard shortcuts

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