ecache

package
v1.5.3 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package 提供统一的缓存接口

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type E缓存类 added in v1.2.3

type E缓存类 struct {
	// contains filtered or unexported fields
}

缓存适配器

func New缓存类

func New缓存类(缓存 缓存接口) *E缓存类

func (*E缓存类) Del added in v1.2.3

func (c *E缓存类) Del(key string) error

Del

func (*E缓存类) E删除 added in v1.2.3

func (c *E缓存类) E删除(key string) error

E删除

func (*E缓存类) E取值 added in v1.2.3

func (c *E缓存类) E取值(key string) interface{}

E取值

func (*E缓存类) E设置值 added in v1.2.3

func (c *E缓存类) E设置值(key string, value interface{}, 倒计时秒数 int64) error

E设置值

func (*E缓存类) Get added in v1.2.3

func (c *E缓存类) Get(key string) interface{}

Get

func (*E缓存类) GetBool added in v1.2.3

func (c *E缓存类) GetBool(key string) bool

GetBool

func (*E缓存类) GetBytes added in v1.2.3

func (c *E缓存类) GetBytes(key string) []byte

GetBytes

func (*E缓存类) GetFloat added in v1.2.3

func (c *E缓存类) GetFloat(key string) float64

GetFloat

func (*E缓存类) GetInt added in v1.2.3

func (c *E缓存类) GetInt(key string) int64

GetInt

func (*E缓存类) GetString added in v1.2.3

func (c *E缓存类) GetString(key string) string

GetString

func (*E缓存类) Set added in v1.2.3

func (c *E缓存类) Set(key string, value interface{}, 倒计时秒数 int64) error

Set

type File缓存器 added in v1.1.5

type File缓存器 struct {
	// contains filtered or unexported fields
}

文件缓存实现

Example
// 创建缓存适配器
缓存 := New缓存类(NewFile缓存器("./cache/"))

// 设置缓存数据
缓存.Set("a", "1", -160)
缓存.Set("b", 2, 60)
缓存.Set("c", []byte("3"), 60)

// 获取缓存数据
a := 缓存.Get("a")
fmt.Println(a)
if a != nil {
	panic("a != nil")
}
b := 缓存.GetInt("b")
fmt.Println(b)
if b != 2 {
	panic("b != 2")
}
c := 缓存.GetBytes("c")
fmt.Println(c)
if string(c) != "3" {
	panic("string(c) != 3")
}
d := 缓存.Get("d")
fmt.Println(d)
if d != nil {
	panic("d != nil")
}
ecore.E删除目录("./cache/")
Output:

func NewFile缓存器 added in v1.1.5

func NewFile缓存器(存储路径 string) *File缓存器

func (*File缓存器) Del added in v1.1.5

func (fc *File缓存器) Del(key string) error

func (*File缓存器) Get added in v1.1.5

func (fc *File缓存器) Get(key string) (interface{}, error)

func (*File缓存器) Set added in v1.1.5

func (fc *File缓存器) Set(key string, value interface{}, 倒计时秒数 int64) error

type Mem缓存器 added in v1.1.5

type Mem缓存器 struct {
	// contains filtered or unexported fields
}

内存缓存实现

Example
// 创建缓存适配器
缓存 := New缓存类(NewMem缓存器())

// 设置缓存数据
缓存.Set("a", "1", -160)
缓存.Set("b", 2, 60)
缓存.Set("c", []byte("3"), 60)

// 获取缓存数据
a := 缓存.Get("a")
fmt.Println(a)
if a != nil {
	panic("a != nil")
}
b := 缓存.GetInt("b")
fmt.Println(b)
if b != 2 {
	panic("b != 2")
}
c := 缓存.GetBytes("c")
fmt.Println(c)
if string(c) != "3" {
	panic("string(c) != 3")
}
d := 缓存.Get("d")
fmt.Println(d)
if d != nil {
	panic("d != nil")
}
Output:

func NewMem缓存器 added in v1.1.5

func NewMem缓存器() *Mem缓存器

func (*Mem缓存器) Del added in v1.1.5

func (fc *Mem缓存器) Del(key string) error

func (*Mem缓存器) Get added in v1.1.5

func (fc *Mem缓存器) Get(key string) (interface{}, error)

func (*Mem缓存器) Set added in v1.1.5

func (fc *Mem缓存器) Set(key string, value interface{}, 倒计时秒数 int64) error

type Mysql缓存器

type Mysql缓存器 struct {
	// contains filtered or unexported fields
}

Mysql缓存实现

Example
// 创建缓存适配器
缓存 := New缓存类(NewMysql缓存器("root@tcp(127.0.0.1:3310)/gogorm?charset=utf8&parseTime=true&loc=Local"))

// 设置缓存数据
缓存.Set("a", "1", -160)
缓存.Set("b", 2, 60)
缓存.Set("c", []byte("3"), 60)

// 获取缓存数据
a := 缓存.Get("a")
fmt.Println(a)
if a != nil {
	panic("a != nil")
}
b := 缓存.GetInt("b")
fmt.Println(b)
if b != 2 {
	panic("b != 2")
}
c := 缓存.GetBytes("c")
fmt.Println(c)
if string(c) != "3" {
	panic("string(c) != 3")
}
d := 缓存.Get("d")
fmt.Println(d)
if d != nil {
	panic("d != nil")
}
Output:

func NewMysql缓存器

func NewMysql缓存器(数据库连接字符串 string) *Mysql缓存器

NewMysql缓存器 数据库连接字符串 例如:

func (*Mysql缓存器) Del

func (fc *Mysql缓存器) Del(key string) error

func (*Mysql缓存器) Get

func (fc *Mysql缓存器) Get(key string) (interface{}, error)

func (*Mysql缓存器) Set

func (fc *Mysql缓存器) Set(key string, value interface{}, 倒计时秒数 int64) error

type Redis缓存器

type Redis缓存器 struct {
	// contains filtered or unexported fields
}

Redis缓存实现

Example
// 创建缓存适配器
缓存 := New缓存类(NewRedis缓存器("127.0.0.1:6379", "", 1))

// 设置缓存数据
缓存.Set("a", "1", -160)
缓存.Set("b", 2, 60)
缓存.Set("c", []byte("3"), 60)

// 获取缓存数据
a := 缓存.Get("a")
fmt.Println(a)
if a != nil {
	panic("a != nil")
}
b := 缓存.GetInt("b")
fmt.Println(b)
if b != 2 {
	panic("b != 2")
}
c := 缓存.GetBytes("c")
fmt.Println(c)
if string(c) != "3" {
	panic("string(c) != 3")
}
d := 缓存.Get("d")
fmt.Println(d)
if d != nil {
	panic("d != nil")
}
Output:

func NewRedis缓存器

func NewRedis缓存器(link string, password string, db int) *Redis缓存器

NewRedis缓存器 link: redis地址 例如 127.0.0.1:6379 db: redis的db编号 0-15

func (*Redis缓存器) Del

func (fc *Redis缓存器) Del(key string) error

func (*Redis缓存器) Get

func (fc *Redis缓存器) Get(key string) (interface{}, error)

func (*Redis缓存器) Set

func (fc *Redis缓存器) Set(key string, value interface{}, 倒计时秒数 int64) error

type Sqlite缓存器

type Sqlite缓存器 struct {
	// contains filtered or unexported fields
}

Sqlite缓存实现

Example
// 创建缓存适配器
缓存 := New缓存类(NewSqlite缓存器("./cache.db"))

// 设置缓存数据
缓存.Set("a", "1", -160)
缓存.Set("b", 2, 60)
缓存.Set("c", []byte("3"), 60)

// 获取缓存数据
a := 缓存.Get("a")
fmt.Println(a)
if a != nil {
	panic("a != nil")
}
b := 缓存.GetInt("b")
fmt.Println(b)
if b != 2 {
	panic("b != 2")
}
c := 缓存.GetBytes("c")
fmt.Println(c)
if string(c) != "3" {
	panic("string(c) != 3")
}
d := 缓存.Get("d")
fmt.Println(d)
if d != nil {
	panic("d != nil")
}
ecore.E删除文件("./cache.db")
Output:

func NewSqlite缓存器

func NewSqlite缓存器(缓存数据库路径 string) *Sqlite缓存器

func (*Sqlite缓存器) Del

func (fc *Sqlite缓存器) Del(key string) error

func (*Sqlite缓存器) Get

func (fc *Sqlite缓存器) Get(key string) (interface{}, error)

func (*Sqlite缓存器) Set

func (fc *Sqlite缓存器) Set(key string, value interface{}, 倒计时秒数 int64) error

Jump to

Keyboard shortcuts

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