Cache-aside
Cache-aside is a caching pattern in which an application checks the cache before loading data from its primary database. On a cache miss, the application loads the data, stores it with a TTL and returns it; write paths delete the affected cached key.
Minimal example
data, err := rdb.Get(ctx, key).Bytes()
if err == redis.Nil {
data, err = load(ctx)
if err == nil {
_ = rdb.Set(ctx, key, data, ttl).Err()
}
}