Skip to content

mgtv-tech/jetcache-go

Repository files navigation

jetcache-go

banner

Build Status codeCov Go Report Card License Release

Language: 简体中文

Overview

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.

Why jetcache-go

  • Two-level cache: local (FreeCache/TinyLFU) + remote (Redis)
  • Singleflight miss collapse and optional auto-refresh
  • Generic MGet with 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

Feature Availability

  • Generic MGet + load callback + pipeline optimization: v1.1.0+
  • Cross-process local cache invalidation after updates: v1.1.1+

See Versioning for details.

Quick Start

Install:

go get github.com/mgtv-tech/jetcache-go

Minimal 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:

Documentation

Getting started:

Configuration and API:

Production operations:

Contributing

See CONTRIBUTING.md.

License

MIT. See LICENSE.

Contact

Packages

 
 
 

Contributors