cache

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2020 License: MIT Imports: 3 Imported by: 23

README

cache codecov PkgGoDev

通用的缓存接口

目前支持以下组件:

名称 状态
memory 内存 memory
memcached github.com/bradfitz/gomemcache memcache
redis github.com/gomodule/redigo memcache
// memory
c := memory.New()
c.Set("number", 1)
print(c.Get("number"))

// memcached
c = memcache.New(log.New(os.Stderr, "", 0), "localhost:11211")
c.Set("number", 1)
print(c.Get("number"))

安装

go get github.com/issue9/cache

版权

本项目采用 MIT 开源授权许可证,完整的授权说明可在 LICENSE 文件中找到。

Documentation

Overview

Package cache 统一的缓存接口

Index

Constants

View Source
const (
	Forever     = 0 //  永不过时
	OneMinute   = 60
	FiveMinutes = 5 * OneMinute
	TenMinutes  = 10 * OneMinute
	HalfHour    = 30 * OneMinute
	OneHour     = 60 * OneMinute
	HalfDay     = 12 * OneHour
	OneDay      = 24 * OneHour
	OneWeek     = 7 * OneDay
	ThirtyDays  = 30 * OneDay // 30 天
	SixtyDays   = 60 * OneDay // 60 天
	NinetyDays  = 90 * OneDay // 90 天
)

常用时间的定义

Variables

View Source
var ErrCacheMiss = errors.New("cache: 未找到缓存项")

ErrCacheMiss 当不存在缓存项时返回的错误

Functions

func GoDecode

func GoDecode(bs []byte, v interface{}) error

GoDecode 将 bs 内容以 gob 规则解码到 v

func GoEncode

func GoEncode(v interface{}) ([]byte, error)

GoEncode 将 v 转换成 gob 编码

Types

type Cache

type Cache interface {
	// 获取缓存项
	//
	// 当前不存在时,返回 ErrCacheMiss 错误。
	Get(key string) (interface{}, error)

	// 设置或是添加缓存项
	//
	// seconds 表示过了该时间,缓存项将被回收。如果该值为 0,该值永远不会回收。
	Set(key string, val interface{}, seconds int) error

	// 删除一个缓存项
	Delete(key string) error

	// 判断一个缓存项是否存在
	Exists(key string) bool

	// 清除所有的缓存内容
	Clear() error

	// 关闭整个缓存系统
	Close() error
}

Cache 一个统一的缓存接口

Directories

Path Synopsis
internal
testcase
Package testcase 提供测试用例
Package testcase 提供测试用例
Package memcache memcached 客户端的 cache 接口实现
Package memcache memcached 客户端的 cache 接口实现
Package memory 以内存形式存储缓存内容
Package memory 以内存形式存储缓存内容
Package redis redis 客户端的 cache 接口实现
Package redis redis 客户端的 cache 接口实现

Jump to

Keyboard shortcuts

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