memory

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: May 30, 2026 License: Apache-2.0 Imports: 6 Imported by: 6

Documentation

Overview

@Author daixk 2025/12/22 15:56:00

Index

Constants

View Source
const (
	TTLNoExpire = adapter.TTLNoExpire
	TTLNotFound = adapter.TTLNotFound
)

TTL constants define memory TTL sentinel values TTL 常量定义内存 TTL 哨兵值

Variables

View Source
var ErrKeyNotFound = errors.New("key not found")

ErrKeyNotFound indicates the key is missing or expired 表示键不存在或已过期。

Functions

This section is empty.

Types

type Storage

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

Storage implements in-memory storage with go-cache 基于 go-cache 的内存存储实现。

func NewStorage

func NewStorage() *Storage

NewStorage creates a new memory storage instance 创建一个新的内存存储实例

func (*Storage) Clear

func (s *Storage) Clear(_ context.Context) error

Clear removes all stored data 清空所有数据。

func (*Storage) Delete

func (s *Storage) Delete(_ context.Context, keys ...string) error

Delete removes one or more keys 删除一个或多个键

func (*Storage) Exists

func (s *Storage) Exists(_ context.Context, key string) bool

Exists checks whether a key exists and is not expired 检查键是否存在且未过期

func (*Storage) Expire

func (s *Storage) Expire(_ context.Context, key string, expiration time.Duration) error

Expire sets a new expiration for the key 为指定键设置新的过期时间

func (*Storage) Get

func (s *Storage) Get(_ context.Context, key string) (any, error)

Get retrieves the value for a key 获取指定键的值

func (*Storage) GetAndDelete

func (s *Storage) GetAndDelete(_ context.Context, key string) (any, error)

GetAndDelete atomically gets and deletes a key 原子地获取并删除指定键

func (*Storage) Keys

func (s *Storage) Keys(_ context.Context, pattern string) ([]string, error)

Keys returns all keys matching the pattern 返回匹配指定模式的所有键

func (*Storage) Ping

func (s *Storage) Ping(_ context.Context) error

Ping checks whether storage is available 检查存储是否可用

func (*Storage) Set

func (s *Storage) Set(_ context.Context, key string, value any, expiration time.Duration) error

Set stores a key value pair 设置键值对

func (*Storage) TTL

func (s *Storage) TTL(_ context.Context, key string) (time.Duration, error)

TTL returns the remaining lifetime for a key 获取指定键的剩余生存时间

Jump to

Keyboard shortcuts

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