Help us shape the future of Go! Take the 2026 Go Developer Survey

chain

command
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: MIT Imports: 7 Imported by: 0

README

Chain Cache Example

Demonstrates ChainCache[T] — multi-layer caching with automatic backfill.

What it shows

  • Building a two-layer cache: L1 (small, fast) + L2 (larger, slower)
  • Set writes to all layers simultaneously
  • Get tries L1 first; on miss it falls through to L2 and backfills L1 asynchronously
  • Delete removes from all layers
  • GetLayers() to inspect the layer stack

Production pattern

Replace the L2 in-memory store with a Redis store:

redisClient, _ := rueidis.NewClient(rueidis.ClientOption{
    InitAddress: []string{"localhost:6379"},
})
redisStore, _ := redis.New(redis.Config{Client: redisClient})
l2 := cache.New[Session](redisStore, cache.WithTTL(10*time.Minute))

Run

go run ./examples/chain/

Documentation

Overview

Package main demonstrates multi-layer caching with ChainCache (L1 memory + L2 memory).

In production you would replace the L2 memory store with a Redis store.

Jump to

Keyboard shortcuts

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