@@ -7,11 +7,12 @@ A high-performance semantic caching library for Go that uses vector embeddings t
77- 🚀 ** Multiple Backend Support** : In-memory (LRU, LFU, FIFO) and Redis
88- 🤖 ** OpenAI Integration** : Built-in support for OpenAI's embedding models
99- 🎯 ** Semantic Search** : Find similar content using vector similarity
10- - ⚡ ** High Performance** : Optimized similarity algorithms
10+ - ⚡ ** High Performance** : Optimized similarity algorithms with async support
1111- 🛠️ ** Extensible** : Pluggable backends and embedding providers
1212- 📦 ** Type Safe** : Full generic support for any key/value types
1313- 🔄 ** Context Aware** : Built-in context support for all operations
14- - 📊 ** Batch Operations** : Efficient bulk operations
14+ - 📊 ** Batch Operations** : Efficient bulk operations (sync & async)
15+ - ⚙️ ** Async API** : Non-blocking operations with channel-based results
1516
1617## Quick Start
1718
@@ -166,6 +167,61 @@ values, err := cache.GetBatch(ctx, []string{"key1", "key2"})
166167err := cache.DeleteBatch (ctx, []string {" key1" , " key2" })
167168```
168169
170+ ### Async Operations
171+
172+ All cache operations have async variants that return channels for non-blocking execution:
173+
174+ ``` go
175+ // Async set - returns immediately
176+ errCh := cache.SetAsync (ctx, " key" , " input text" , " value" )
177+ // Do other work...
178+ if err := <- errCh; err != nil {
179+ log.Printf (" Set failed: %v " , err)
180+ }
181+
182+ // Async get
183+ resultCh := cache.GetAsync (ctx, " key" )
184+ result := <- resultCh
185+ if result.Error != nil {
186+ log.Printf (" Get failed: %v " , result.Error )
187+ }
188+ if result.Found {
189+ fmt.Printf (" Value: %v \n " , result.Value )
190+ }
191+
192+ // Async semantic search
193+ lookupCh := cache.LookupAsync (ctx, " search query" , 0.8 )
194+ lookupResult := <- lookupCh
195+ if lookupResult.Match != nil {
196+ fmt.Printf (" Found: %v (score: %.2f )\n " ,
197+ lookupResult.Match .Value , lookupResult.Match .Score )
198+ }
199+
200+ // Async batch operations for concurrent processing
201+ errCh = cache.SetBatchAsync (ctx, items)
202+ err = <- errCh
203+
204+ valuesCh := cache.GetBatchAsync (ctx, []string {" key1" , " key2" , " key3" })
205+ batchResult := <- valuesCh
206+ if batchResult.Error == nil {
207+ for key , value := range batchResult.Values {
208+ fmt.Printf (" %s : %v \n " , key, value)
209+ }
210+ }
211+
212+ // Concurrent async operations
213+ errCh1 := cache.SetAsync (ctx, " key1" , " text1" , " value1" )
214+ errCh2 := cache.SetAsync (ctx, " key2" , " text2" , " value2" )
215+ errCh3 := cache.SetAsync (ctx, " key3" , " text3" , " value3" )
216+
217+ // Wait for all to complete
218+ for _ , ch := range []<- chan error {errCh1, errCh2, errCh3} {
219+ if err := <- ch; err != nil {
220+ log.Printf (" Operation failed: %v " , err)
221+ }
222+ }
223+ ```
224+
169225## Advanced Usage
170226
171227### Custom Embedding Provider
0 commit comments