Loading documentation...
Loading documentation...
Loading documentation...
Synapse is a high-performance, generic similarity-based cache for Go with intelligent sharding and pluggable eviction policies.
Synapse is a thread-safe, context-aware cache that goes beyond traditional key-value storage by supporting similarity-based lookups. When an exact key match isn't found, Synapse can find the "closest" matching key based on a configurable similarity function and threshold.
This makes Synapse ideal for:
| Feature | Description |
|---|---|
| Similarity-Based Lookups | Find approximate matches when exact keys don't exist |
| Generic Types | Fully type-safe with Go generics (1.24+) |
| High Performance | Automatic sharding distributes load across concurrent-safe partitions |
| Pluggable Similarity | Define custom similarity algorithms for your use case |
| Eviction Policies | LRU with support for combined policies |
| TTL Support | Automatic expiration of cache entries |
| Namespace Isolation | Partition cache entries by namespace via context |
| Thread-Safe | RWMutex-protected reads and writes per shard |
| Metadata Support | Attach custom metadata to cache entries |
| Context-Aware | Full context.Context integration for cancellation |
| Zero Dependencies | Only uses Go standard library |
github.com/kolosys/synapseSynapse is organized into three packages:
synapse (main package)The core cache implementation with:
Cache[K, V] - Generic similarity-based cacheEntry[K, V] - Cache entry with metadataShard[K, V] - Individual cache shardsynapse/algorithmsBuilt-in similarity algorithms:
synapse/evictionPluggable eviction policies:
| Section | Description |
|---|---|
| Getting Started | Installation and quick start guides |
| Core Concepts | Architecture and fundamental concepts |
| Advanced Topics | Performance tuning and best practices |
| API Reference | Complete API documentation |
| Examples | Working code examples |
package main
import (
"context"
"fmt"
"github.com/kolosys/synapse"
"github.com/kolosys/synapse/algorithms"
"github.com/kolosys/synapse/eviction"
)
func main() {
ctx := context.Background()
// Create cache with LRU eviction
cache := synapse.New[string, string](
synapse.WithMaxSize(1000),
synapse.WithThreshold(0.7),
synapse.WithEviction(eviction.NewLRU(1000)),
)
// Set similarity function using Levenshtein distance
cache.WithSimilarity(algorithms.Levenshtein)
// Store values
cache.Set(ctx, "hello world", "greeting")
cache.Set(ctx, "goodbye world", "farewell")
// Exact match
if value, found := cache.Get(ctx, "hello world"); found {
fmt.Println("Exact:", value) // Output: Exact: greeting
}
// Similarity search
value, key, score, found := cache.GetSimilar(ctx, "hello wrold")
if found {
fmt.Printf("Similar: %s (key: %s, score: %.2f)
", value, key, score)
// Output: Similar: greeting (key: hello world, score: 0.91)
}
}Synapse is a high-performance, generic similarity-based cache for Go with intelligent sharding and pluggable eviction policies.
Synapse is a thread-safe, context-aware cache that goes beyond traditional key-value storage by supporting similarity-based lookups. When an exact key match isn't found, Synapse can find the "closest" matching key based on a configurable similarity function and threshold.
This makes Synapse ideal for:
| Feature | Description |
|---|---|
| Similarity-Based Lookups | Find approximate matches when exact keys don't exist |
| Generic Types | Fully type-safe with Go generics (1.24+) |
| High Performance | Automatic sharding distributes load across concurrent-safe partitions |
| Pluggable Similarity | Define custom similarity algorithms for your use case |
| Eviction Policies | LRU with support for combined policies |
| TTL Support | Automatic expiration of cache entries |
| Namespace Isolation | Partition cache entries by namespace via context |
| Thread-Safe | RWMutex-protected reads and writes per shard |
| Metadata Support | Attach custom metadata to cache entries |
| Context-Aware | Full context.Context integration for cancellation |
| Zero Dependencies | Only uses Go standard library |
github.com/kolosys/synapseSynapse is organized into three packages:
synapse (main package)The core cache implementation with:
Cache[K, V] - Generic similarity-based cacheEntry[K, V] - Cache entry with metadataShard[K, V] - Individual cache shardsynapse/algorithmsBuilt-in similarity algorithms:
synapse/evictionPluggable eviction policies:
| Section | Description |
|---|---|
| Getting Started | Installation and quick start guides |
| Core Concepts | Architecture and fundamental concepts |
| Advanced Topics | Performance tuning and best practices |
| API Reference | Complete API documentation |
| Examples | Working code examples |
package main
import (
"context"
"fmt"
"github.com/kolosys/synapse"
"github.com/kolosys/synapse/algorithms"
"github.com/kolosys/synapse/eviction"
)
func main() {
ctx := context.Background()
// Create cache with LRU eviction
cache := synapse.New[string, string](
synapse.WithMaxSize(1000),
synapse.WithThreshold(0.7),
synapse.WithEviction(eviction.NewLRU(1000)),
)
// Set similarity function using Levenshtein distance
cache.WithSimilarity(algorithms.Levenshtein)
// Store values
cache.Set(ctx, "hello world", "greeting")
cache.Set(ctx, "goodbye world", "farewell")
// Exact match
if value, found := cache.Get(ctx, "hello world"); found {
fmt.Println("Exact:", value) // Output: Exact: greeting
}
// Similarity search
value, key, score, found := cache.GetSimilar(ctx, "hello wrold")
if found {
fmt.Printf("Similar: %s (key: %s, score: %.2f)
", value, key, score)
// Output: Similar: greeting (key: hello world, score: 0.91)
}
}package main
import (
"context"
"fmt"
"github.com/kolosys/synapse"
"github.com/kolosys/synapse/algorithms"
"github.com/kolosys/synapse/eviction"
)
func main() {
ctx := context.Background()
// Create cache with LRU eviction
cache := synapse.New[string, string](
synapse.WithMaxSize(1000),
synapse.WithThreshold(0.7),
synapse.WithEviction(eviction.NewLRU(1000)),
)
// Set similarity function using Levenshtein distance
cache.WithSimilarity(algorithms.Levenshtein)
// Store values
cache.Set(ctx, "hello world", "greeting")
cache.Set(ctx, "goodbye world", "farewell")
// Exact match
if value, found := cache.Get(ctx, "hello world"); found {
fmt.Println("Exact:", value) // Output: Exact: greeting
}
// Similarity search
value, key, score, found := cache.GetSimilar(ctx, "hello wrold")
if found {
fmt.Printf("Similar: %s (key: %s, score: %.2f)
", value, key, score)
// Output: Similar: greeting (key: hello world, score: 0.91)
}
}package main
import (
"context"
"fmt"
"github.com/kolosys/synapse"
"github.com/kolosys/synapse/algorithms"
"github.com/kolosys/synapse/eviction"
)
func main() {
ctx := context.Background()
// Create cache with LRU eviction
cache := synapse.New[string, string](
synapse.WithMaxSize(1000),
synapse.WithThreshold(0.7),
synapse.WithEviction(eviction.NewLRU(1000)),
)
// Set similarity function using Levenshtein distance
cache.WithSimilarity(algorithms.Levenshtein)
// Store values
cache.Set(ctx, "hello world", "greeting")
cache.Set(ctx, "goodbye world", "farewell")
// Exact match
if value, found := cache.Get(ctx, "hello world"); found {
fmt.Println("Exact:", value) // Output: Exact: greeting
}
// Similarity search
value, key, score, found := cache.GetSimilar(ctx, "hello wrold")
if found {
fmt.Printf("Similar: %s (key: %s, score: %.2f)
", value, key, score)
// Output: Similar: greeting (key: hello world, score: 0.91)
}
}