cache

package
v0.0.0-...-183aa75 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusOK = "OK"
)

Variables

View Source
var (
	ErrKeysOverCapacity = errors.New("keys over capacity")
	ErrFilenameEmpty    = errors.New("save filename empty")
)

Functions

func FilenameExists

func FilenameExists(filename string) bool

func GetCurrentDir

func GetCurrentDir() (string, error)

Types

type BoolCmd

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

func (*BoolCmd) Error

func (cmd *BoolCmd) Error() error

func (*BoolCmd) Exists

func (cmd *BoolCmd) Exists() bool

func (*BoolCmd) TTL

func (cmd *BoolCmd) TTL() time.Duration

func (*BoolCmd) Val

func (cmd *BoolCmd) Val() bool

type Cache

type Cache interface {
	Get(key string) *Cmd
	Set(key string, value interface{}, ttl time.Duration) *StatusCmd

	// prefix - 前缀查询,"" 查询所有, 只返回当前有效的key
	Keys(prefix string) *SliceStringCmd

	Delete(key string) *StatusCmd

	// 删除所有 key
	FlushAll() *StatusCmd

	Save() *StatusCmd

	Close() error
}

type Cmd

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

func (*Cmd) Error

func (cmd *Cmd) Error() error

func (*Cmd) Exists

func (cmd *Cmd) Exists() bool

func (*Cmd) TTL

func (cmd *Cmd) TTL() time.Duration

func (*Cmd) Val

func (cmd *Cmd) Val() interface{}

func (*Cmd) ValString

func (cmd *Cmd) ValString() string

type Disk

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

func NewDisk

func NewDisk(filename string) (*Disk, error)

NewDisk filename

func (*Disk) ReadFromFile

func (d *Disk) ReadFromFile() ([]byte, error)

ReadFromFile

func (*Disk) WriteToFile

func (d *Disk) WriteToFile(data []byte) error

WriteToFile 如果之前文件存在,则删除

type MemCache

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

func NewMemCache

func NewMemCache(opts ...Options) *MemCache

func (*MemCache) Close

func (mem *MemCache) Close() error

Close 开启写入磁盘,则写入文件

func (*MemCache) Delete

func (mem *MemCache) Delete(key string) *StatusCmd

func (*MemCache) FlushAll

func (mem *MemCache) FlushAll() *StatusCmd

FlushAll 清空所有数据

func (*MemCache) Get

func (mem *MemCache) Get(key string) *Cmd

func (*MemCache) Keys

func (mem *MemCache) Keys(prefix string) *SliceStringCmd

func (*MemCache) Save

func (mem *MemCache) Save() *StatusCmd

func (*MemCache) Set

func (mem *MemCache) Set(key string, value interface{}, ttl time.Duration) *StatusCmd

type Options

type Options struct {
	// 缓存容量, 默认 -1  不限制  byte
	Size int32
	// 自动清除, 当ttl key存在不多时,可以关闭,默认关闭
	AutoClean bool
	// 保存文件位置, 默认 不设置,不能 Save
	Filename string
}

func NewDefaultOptions

func NewDefaultOptions() Options

type SliceStringCmd

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

func (*SliceStringCmd) Error

func (cmd *SliceStringCmd) Error() error

func (*SliceStringCmd) Exists

func (cmd *SliceStringCmd) Exists() bool

func (*SliceStringCmd) TTL

func (cmd *SliceStringCmd) TTL() time.Duration

func (*SliceStringCmd) Val

func (cmd *SliceStringCmd) Val() []string

type StatusCmd

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

func (*StatusCmd) Error

func (cmd *StatusCmd) Error() error

func (*StatusCmd) Exists

func (cmd *StatusCmd) Exists() bool

func (*StatusCmd) TTL

func (cmd *StatusCmd) TTL() time.Duration

type WrapValue

type WrapValue struct {
	Value       interface{} `json:"v"`
	ExpiredTime time.Time   `json:"e"`
	Size        int32       `json:"s"`
}

func (*WrapValue) Expired

func (val *WrapValue) Expired() bool

func (*WrapValue) SetExpiredTime

func (val *WrapValue) SetExpiredTime(t time.Duration)

func (*WrapValue) TTL

func (val *WrapValue) TTL() time.Duration

Jump to

Keyboard shortcuts

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