Language: 简体中文
jetcache-go is a production-grade cache framework for Go. It is inspired by Java JetCache and extends the go-redis/cache model with two-level caching, singleflight-based miss protection, typed batch APIs, and operational features for large-scale services.
- Two-level cache: local (
FreeCache/TinyLFU) + remote (Redis) - Singleflight miss collapse and optional auto-refresh
- Generic
MGetwith pipeline optimization - Cache penetration protection via not-found placeholder strategy
- Built-in stats and Prometheus plugin integration
- Interface-driven design for local/remote/codec/stats extensions
- Generic
MGet+ load callback + pipeline optimization:v1.1.0+ - Cross-process local cache invalidation after updates:
v1.1.1+
See Versioning for details.
Install:
go get github.com/mgtv-tech/jetcache-goMinimal usage:
package main
import (
"context"
"time"
cache "github.com/mgtv-tech/jetcache-go"
"github.com/mgtv-tech/jetcache-go/local"
"github.com/mgtv-tech/jetcache-go/remote"
"github.com/redis/go-redis/v9"
)
func main() {
rdb := redis.NewClient(&redis.Options{Addr: "127.0.0.1:6379"})
c := cache.New(
cache.WithName("user-cache"),
cache.WithLocal(local.NewTinyLFU(100_000, time.Minute)),
cache.WithRemote(remote.NewGoRedisV9Adapter(rdb)),
)
defer c.Close()
var user string
_ = c.Once(context.Background(), "user:1001",
cache.Value(&user),
cache.Do(func(context.Context) (any, error) {
return "alice", nil
}),
)
}See full quick start and scenarios:
Getting started:
Configuration and API:
Production operations:
See CONTRIBUTING.md.
MIT. See LICENSE.
- Email:
daoshenzzg@gmail.com - Issues: https://github.com/mgtv-tech/jetcache-go/issues
