百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
C

cache

> 数据库
开源

通用缓存使用和缓存管理。通过封装各种常用驱动程序,提供统一的使用 API。支持文件、内存、Redis、Memcached 等。

197 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

通用缓存使用和缓存管理。通过封装各种常用驱动程序,提供统一的使用 API。支持文件、内存、Redis、Memcached 等。

Cache

中文说明

Generic cache use and cache manager for golang.

Provide a unified usage API by packaging various commonly used drivers.

All cache driver implemented the cache.Cache interface. So, You can add any custom driver.

Packaged Drivers:

  • goredis https://github.com/go-redis/redis
  • redis https://github.com/gomodule/redigo
  • memcached https://github.com/bradfitz/gomemcache
  • buntdb https://github.com/tidwall/buntdb
  • boltdb https://github.com/etcd-io/bbolt
  • badger https://github.com/dgraph-io/badger
  • nutsdb https://github.com/xujiajun/nutsdb
  • goleveldb https://github.com/syndtr/goleveldb
  • gcache https://github.com/bluele/gcache
  • gocache https://github.com/patrickmn/go-cache
  • bigcache https://github.com/allegro/bigcache

Internal:

  • file internal driver driver_file.go
  • memory internal driver driver_memory.go

Notice: The built-in implementation is relatively simple and is not recommended for production environments; the production environment recommends using the third-party drivers listed above.

GoDoc

  • doc on gowalker
  • godoc for gopkg
  • godoc for github

Install

The package supports 3 last Go versions and requires a Go version with modules support.

bash
go get github.com/gookit/cache

Cache Interface

All cache driver implemented the cache.Cache interface. So, You can add any custom driver.

go
type Cache interface {
	// basic operation
	Has(key string) bool
	Get(key string) any
	Set(key string, val any, ttl time.Duration) (err error)
	Del(key string) error
	// multi operation
	GetMulti(keys []string) map[string]any
	SetMulti(values map[string]any, ttl time.Duration) (err error)
	DelMulti(keys []string) error
	// clear and close
	Clear() error
	Close() error
}

Usage

…

With Options

go
gords := goredis.Connect("127.0.0.1:6379", "", 0)
gords.WithOptions(cache.WithPrefix("cache_"), cache.WithEncode(true))

cache.Register(goredis.Name, gords)

// set
// real key is: "cache_name"
cache.Set("name", "cache value", cache.TwoMinutes)

// get: "cache value"
val := cache.Get("name")

Gookit packages

  • gookit/ini Go config management, use INI files
  • gookit/rux Simple and fast request router for golang HTTP
  • gookit/gcli build CLI application, tool library, running CLI commands
  • gookit/slog Lightweight, extensible, configurable logging library written in Go
  • gookit/event Lightweight event manager and dispatcher implements by Go
  • gookit/cache Provide a unified usage API by packaging various commonly used drivers.
  • gookit/config Go config management. support JSON, YAML, TOML, INI, HCL, ENV and Flags
  • gookit/color A command-line color library with true color support, universal API methods and Windows support
  • gookit/filter Provide filtering, sanitizing, and conversion of golang data
  • gookit/validate Use for data validation and filtering. support Map, Struct, Form data
  • gookit/goutil Some utils for the Go: string, array/slice, map, format, cli, env, filesystem, test and more
  • More, please see https://github.com/gookit

License

MIT

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Gobuntdbcachecache-managercustom-driver

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类数据库
定价开源

> 相关工具

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库