Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Open more actions menu

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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.