Presets
The presets package offers pre-configured factory functions to simplify Warp initialization for common use cases. Instead of manually wiring the Cache, Store, Bus, and Engine, you can use these one-liners to get a production-ready setup.
v1/presets
import "github.com/mirkobrombin/go-warp/v1/presets"
NewRedisEventual
Creates a Warp instance tailored for high-performance caching where eventual consistency is acceptable.
- Architecture:
- L1: In-Memory Cache (LRU).
- L2: Redis Store.
- Bus: Redis Pub/Sub (for eventual invalidation).
- Consistency: Optimized for
ModeEventualDistributed(writes go to L2, asynchronous invalidation to L1 peers).
- L1: In-Memory Cache (LRU).
w := presets.NewRedisEventual[User](presets.RedisOptions{
Addr: "localhost:6379",
})
NewRedisStrong
Creates a Warp instance tailored for strong consistency.
- Architecture:
- L1: In-Memory Cache.
- L2: Redis Store.
- Bus: Redis Pub/Sub.
- Consistency: Optimized for
ModeStrongDistributed(writes wait for quorum/acknowledgment before returning).
- L1: In-Memory Cache.
w := presets.NewRedisStrong[Config](presets.RedisOptions{
Addr: "localhost:6379",
})
// Remember to register keys with ModeStrongDistributed
w.Register("config:*", core.ModeStrongDistributed, 24*time.Hour)
w.SetQuorum("config:*", 3)
[!NOTE]
Strong consistency requires all nodes to be reachable to satisfy quorum.
NewMeshEventual
Creates a Warp instance using Warp Mesh (UDP P2P) for synchronization with zero external infrastructure.
- Architecture:
- L1: In-Memory Cache.
- L2: In-Memory Store.
- Bus: Warp Mesh (UDP P2P).
- Consistency: Eventual (writes go to L1, invalidation propagated via Mesh).
- L1: In-Memory Cache.
w := presets.NewMeshEventual[MyData](mesh.MeshOptions{
Port: 7946,
})
NewInMemoryStandalone
Creates a fully isolated Warp instance with no external dependencies. Useful for local development, testing, or simplistic single-node caching.
- Architecture:
- L1: In-Memory Cache.
- L2: In-Memory Store (map).
- Bus: In-Memory Bus (messages simulate network delay locally).
- L1: In-Memory Cache.
w := presets.NewInMemoryStandalone[Session]()
NewNATSEventual
Creates a Warp instance using NATS Core as the synchronization bus. L2 is in-memory per node, making this preset suitable when NATS is already present in the infrastructure but a shared persistent store is not required.
- Architecture:
- L1: In-Memory Cache.
- L2: In-Memory Store (per node).
- Bus: NATS Core Pub/Sub.
- Consistency: Eventual.
- L1: In-Memory Cache.
nc, _ := nats.Connect(nats.DefaultURL)
w := presets.NewNATSEventual[MyData](presets.NATSOptions{Conn: nc})
NewNATSStrong
Expresses user intent for strong consistency with NATS Core as the bus. The underlying configuration is identical to NewNATSEventual — NATS Core does not support topology-aware quorum. Full quorum across nodes requires NATS JetStream (future work).
- Architecture:
- L1: In-Memory Cache.
- L2: In-Memory Store (per node).
- Bus: NATS Core Pub/Sub.
- Consistency: Eventual (strong is a usage hint).
- L1: In-Memory Cache.
nc, _ := nats.Connect(nats.DefaultURL)
w := presets.NewNATSStrong[Config](presets.NATSOptions{Conn: nc})
[!NOTE]
Full quorum-based strong consistency with NATS requires JetStream and is planned for a future preset.