cache

package module
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 11 Imported by: 7

README

cache

cache 是 infrago 的模块

包定位

  • 类型:模块
  • 作用:统一缓存模块,负责缓存读写与多后端抽象。

主要功能

  • 对上提供统一模块接口
  • 对下通过驱动接口接入具体后端
  • 支持按配置切换驱动实现

快速接入

import _ "github.com/infrago/cache"
[cache]
driver = "default"

驱动实现接口列表

以下接口由驱动实现(来自模块 driver.go):

Driver
  • Connect(*Instance) (Connect, error)
Connect
  • Open() error
  • Close() error
  • Read(string) ([]byte, error)
  • Write(key string, val []byte, expire time.Duration) error
  • Exists(key string) (bool, error)
  • Delete(key string) error
  • Sequence(key string, start, step int64, expire time.Duration) (int64, error)
  • Keys(prefix string) ([]string, error)
  • Clear(prefix string) error

全局配置项(所有配置键)

配置段:[cache]

  • 未检测到配置键(请查看模块源码的 configure 逻辑)

说明

  • setting 一般用于向具体驱动透传专用参数
  • 多实例配置请参考模块源码中的 Config/configure 处理逻辑

Documentation

Index

Constants

View Source
const NAME = "CACHE"

Variables

View Source
var ErrInvalidConnection = errors.New("Invalid cache connection.")

Functions

func Clear

func Clear(prefixs ...string) error

func ClearFrom

func ClearFrom(conn string, prefixs ...string) error

func Delete

func Delete(key string) error

func DeleteFrom

func DeleteFrom(conn, key string) error

func Exists

func Exists(key string) (bool, error)

func ExistsIn

func ExistsIn(conn, key string) (bool, error)

func Keys

func Keys(prefixs ...string) ([]string, error)

func KeysFrom

func KeysFrom(conn string, prefixs ...string) ([]string, error)

func Read

func Read(key string) (Map, error)

func ReadData

func ReadData(key string) ([]byte, error)

func ReadDataFrom

func ReadDataFrom(conn, key string) ([]byte, error)

func ReadFrom

func ReadFrom(conn, key string) (Map, error)

func Sequence

func Sequence(key string, start, step int64, expires ...time.Duration) (int64, error)

func SequenceOn

func SequenceOn(conn, key string, start, step int64, expires ...time.Duration) (int64, error)

func Write

func Write(key string, value Map, expires ...time.Duration) error

func WriteData

func WriteData(key string, data []byte, expires ...time.Duration) error

func WriteDataTo

func WriteDataTo(conn, key string, data []byte, expires ...time.Duration) error

func WriteTo

func WriteTo(conn, key string, value Map, expires ...time.Duration) error

Types

type Config

type Config struct {
	Driver  string
	Weight  int
	Prefix  string
	Codec   string
	Expire  time.Duration
	Setting Map
}

type Configs

type Configs map[string]Config

type Connect

type Connect interface {
	Open() error
	Close() error

	Read(string) ([]byte, error)
	Write(key string, val []byte, expire time.Duration) error
	Exists(key string) (bool, error)
	Delete(key string) error
	Sequence(key string, start, step int64, expire time.Duration) (int64, error)
	Keys(prefix string) ([]string, error)
	Clear(prefix string) error
}

type Driver

type Driver interface {
	Connect(*Instance) (Connect, error)
}

type Instance

type Instance struct {
	Name    string
	Config  Config
	Setting Map
	// contains filtered or unexported fields
}

type Module

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

func (*Module) Clear

func (m *Module) Clear(prefixs ...string) error

func (*Module) ClearFrom

func (m *Module) ClearFrom(conn string, prefixs ...string) error

func (*Module) Close added in v0.7.0

func (m *Module) Close()

func (*Module) Config

func (m *Module) Config(Map)

func (*Module) Delete

func (m *Module) Delete(key string) error

func (*Module) DeleteFrom

func (m *Module) DeleteFrom(conn, key string) error

func (*Module) Exists

func (m *Module) Exists(key string) (bool, error)

func (*Module) ExistsIn

func (m *Module) ExistsIn(conn, key string) (bool, error)

func (*Module) Keys

func (m *Module) Keys(prefixs ...string) ([]string, error)

func (*Module) KeysFrom

func (m *Module) KeysFrom(conn string, prefixs ...string) ([]string, error)

func (*Module) Open added in v0.7.0

func (m *Module) Open()

func (*Module) Read

func (m *Module) Read(key string) (Map, error)

func (*Module) ReadData

func (m *Module) ReadData(key string) ([]byte, error)

func (*Module) ReadDataFrom

func (m *Module) ReadDataFrom(conn, key string) ([]byte, error)

func (*Module) ReadFrom

func (m *Module) ReadFrom(conn, key string) (Map, error)

func (*Module) Register

func (m *Module) Register(name string, value Any)

func (*Module) RegisterConfig added in v0.7.0

func (m *Module) RegisterConfig(name string, config Config)

func (*Module) RegisterConfigs added in v0.7.0

func (m *Module) RegisterConfigs(configs Configs)

func (*Module) RegisterDriver added in v0.7.0

func (m *Module) RegisterDriver(name string, driver Driver)

func (*Module) Sequence

func (m *Module) Sequence(key string, start, step int64, expires ...time.Duration) (int64, error)

func (*Module) SequenceOn

func (m *Module) SequenceOn(conn, key string, start, step int64, expires ...time.Duration) (int64, error)

func (*Module) Setup added in v0.7.0

func (m *Module) Setup()

func (*Module) Start added in v0.7.0

func (m *Module) Start()

func (*Module) Stop added in v0.7.0

func (m *Module) Stop()

func (*Module) Write

func (m *Module) Write(key string, val Map, expires ...time.Duration) error

func (*Module) WriteData

func (m *Module) WriteData(key string, data []byte, expires ...time.Duration) error

func (*Module) WriteDataTo

func (m *Module) WriteDataTo(conn, key string, data []byte, expires ...time.Duration) error

func (*Module) WriteTo

func (m *Module) WriteTo(conn string, key string, val Map, expires ...time.Duration) error

Jump to

Keyboard shortcuts

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