caches

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2024 License: MIT Imports: 3 Imported by: 0

README

caches

caches 下所有子目录的 github action 只能跑在 linux 系统,作为独立的包,不影响其它包在所有系统上运行。

Documentation

Overview

Package caches 内置的缓存接口实现

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(v any) ([]byte, error)

Marshal 序列化对象

这是 [cache.Cache] 存储对象时的转换方法,按以下顺序进行:

Unmarshal 按同样的顺序执行。

大部分时候 [cache.Driver] 的实现者直接调用此方法即可, 如果需要自己实现,需要注意 Serializer 接口的判断。

func Unmarshal

func Unmarshal(bs []byte, v any) error

Types

type Serializer added in v0.10.0

type Serializer interface {
	MarshalCache() ([]byte, error)
	UnmarshalCache([]byte) error
}

Serializer 缓存系统存取数据时采用的序列化方法

如果你存储的对象实现了该接口,那么在存取数据时,会采用此方法将对象进行编解码。 否则会采用默认的方法进行编辑码。

实现 Serializer 可以拥有更高效的转换效率,以及一些默认行为不可实现的功能, 比如需要对拥有不可导出的字段进行编解码。

NOTE: 必须要有自定义的序列化接口,而不是直接采用 encoding.TextMarshaler 防止无意中改变了 JSON 的编码方式。

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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