|
| 1 | +# obcache-go v1.0.0 Release Notes |
| 2 | + |
| 3 | +🎉 **Initial stable release of obcache-go** - A high-performance, thread-safe caching library for Go. |
| 4 | + |
| 5 | +## 🚀 What is obcache-go? |
| 6 | + |
| 7 | +obcache-go is a powerful caching library designed for modern Go applications. It provides automatic function wrapping, multiple backend support, and production-ready features that make caching both simple and powerful. |
| 8 | + |
| 9 | +## ✨ Key Features |
| 10 | + |
| 11 | +### 🎯 **Function Wrapping (Primary Feature)** |
| 12 | +```go |
| 13 | +// Turn any function into a cached version |
| 14 | +cachedFunc := obcache.Wrap(cache, expensiveFunction) |
| 15 | +result, _ := cachedFunc(args...) // Automatic caching! |
| 16 | +``` |
| 17 | + |
| 18 | +### 🏪 **Multiple Backends** |
| 19 | +- **Memory**: High-performance in-memory caching |
| 20 | +- **Redis**: Distributed caching for multi-instance deployments |
| 21 | + |
| 22 | +### 🔧 **Advanced Features** |
| 23 | +- **TTL Support**: Time-based expiration with automatic cleanup |
| 24 | +- **LRU/LFU/FIFO Eviction**: Multiple eviction strategies |
| 25 | +- **Compression**: Gzip/Deflate compression for large values |
| 26 | +- **Thread Safety**: Optimized concurrent access |
| 27 | +- **Statistics**: Hit rates, miss counts, performance metrics |
| 28 | +- **Hooks**: Event callbacks for monitoring and debugging |
| 29 | +- **Singleflight**: Prevents duplicate concurrent function calls |
| 30 | + |
| 31 | +### 📊 **Monitoring & Observability** |
| 32 | +- Prometheus metrics integration |
| 33 | +- OpenTelemetry support |
| 34 | +- Built-in statistics and hit rate tracking |
| 35 | +- Event hooks for custom monitoring |
| 36 | + |
| 37 | +## 🎯 **Why Choose obcache-go?** |
| 38 | + |
| 39 | +1. **Simplicity**: One line to cache any function - `obcache.Wrap(cache, fn)` |
| 40 | +2. **Performance**: Optimized for high-concurrency scenarios |
| 41 | +3. **Flexibility**: Memory or Redis backends, multiple eviction strategies |
| 42 | +4. **Production Ready**: Comprehensive testing, monitoring, and error handling |
| 43 | +5. **Type Safety**: Full Go generics support for type-safe caching |
| 44 | + |
| 45 | +## 📚 **Quick Start** |
| 46 | + |
| 47 | +```go |
| 48 | +package main |
| 49 | + |
| 50 | +import ( |
| 51 | + "fmt" |
| 52 | + "time" |
| 53 | + "github.com/vnykmshr/obcache-go/pkg/obcache" |
| 54 | +) |
| 55 | + |
| 56 | +func expensiveFunction(id int) (string, error) { |
| 57 | + time.Sleep(100 * time.Millisecond) // Simulate work |
| 58 | + return fmt.Sprintf("result-%d", id), nil |
| 59 | +} |
| 60 | + |
| 61 | +func main() { |
| 62 | + cache, _ := obcache.New(obcache.NewDefaultConfig()) |
| 63 | + |
| 64 | + // Wrap function with caching |
| 65 | + cachedFunc := obcache.Wrap(cache, expensiveFunction) |
| 66 | + |
| 67 | + // First call: slow (cache miss) |
| 68 | + result1, _ := cachedFunc(123) |
| 69 | + |
| 70 | + // Second call: fast (cache hit) |
| 71 | + result2, _ := cachedFunc(123) |
| 72 | + |
| 73 | + fmt.Println(result1, result2) // Same result, much faster |
| 74 | +} |
| 75 | +``` |
| 76 | + |
| 77 | +## 📦 **Installation** |
| 78 | + |
| 79 | +```bash |
| 80 | +go get github.com/vnykmshr/obcache-go |
| 81 | +``` |
| 82 | + |
| 83 | +Requires Go 1.21+ for generics support. |
| 84 | + |
| 85 | +## 🎨 **Configuration Examples** |
| 86 | + |
| 87 | +### Memory Cache |
| 88 | +```go |
| 89 | +config := obcache.NewDefaultConfig(). |
| 90 | + WithMaxEntries(1000). |
| 91 | + WithDefaultTTL(30 * time.Minute) |
| 92 | +cache, _ := obcache.New(config) |
| 93 | +``` |
| 94 | + |
| 95 | +### Redis Cache |
| 96 | +```go |
| 97 | +config := obcache.NewRedisConfig("localhost:6379"). |
| 98 | + WithRedis(&obcache.RedisConfig{KeyPrefix: "myapp:"}) |
| 99 | +cache, _ := obcache.New(config) |
| 100 | +``` |
| 101 | + |
| 102 | +### With Compression |
| 103 | +```go |
| 104 | +config := obcache.NewDefaultConfig(). |
| 105 | + WithCompression(&compression.Config{ |
| 106 | + Enabled: true, |
| 107 | + Algorithm: compression.CompressorGzip, |
| 108 | + MinSize: 1000, // Only compress values > 1KB |
| 109 | + }) |
| 110 | +``` |
| 111 | + |
| 112 | +## 📈 **Performance** |
| 113 | + |
| 114 | +- **Concurrent reads/writes**: Optimized locking strategy |
| 115 | +- **Memory efficient**: LRU eviction prevents unbounded growth |
| 116 | +- **Fast key generation**: Efficient hashing for complex keys |
| 117 | +- **Singleflight**: Eliminates duplicate work under high load |
| 118 | + |
| 119 | +## 🧪 **Examples** |
| 120 | + |
| 121 | +The release includes comprehensive examples: |
| 122 | + |
| 123 | +- **[Basic Usage](examples/basic/main.go)** - Simple cache operations |
| 124 | +- **[Redis Backend](examples/redis-cache/main.go)** - Distributed caching |
| 125 | +- **[Compression](examples/compression/main.go)** - Value compression |
| 126 | +- **[Metrics Integration](examples/metrics/main.go)** - Prometheus/OpenTelemetry |
| 127 | +- **[Web Server](examples/gin-web-server/main.go)** - Real-world usage |
| 128 | + |
| 129 | +## 🔄 **Migration from other libraries** |
| 130 | + |
| 131 | +### From go-cache: |
| 132 | +```go |
| 133 | +// Before (go-cache) |
| 134 | +import "github.com/patrickmn/go-cache" |
| 135 | +c := cache.New(5*time.Minute, 10*time.Minute) |
| 136 | + |
| 137 | +// After (obcache-go) |
| 138 | +import "github.com/vnykmshr/obcache-go/pkg/obcache" |
| 139 | +cache, _ := obcache.New(obcache.NewDefaultConfig()) |
| 140 | +``` |
| 141 | + |
| 142 | +## 🎯 **Best Practices** |
| 143 | + |
| 144 | +1. **Use function wrapping** - More convenient than manual cache operations |
| 145 | +2. **Set appropriate TTLs** - Balance freshness vs performance |
| 146 | +3. **Monitor hit rates** - Aim for >80% hit rate for good effectiveness |
| 147 | +4. **Use Redis for distributed scenarios** - Essential for multi-instance apps |
| 148 | +5. **Enable compression** - For large values (>1KB) to save memory |
| 149 | + |
| 150 | +## 🔗 **Links** |
| 151 | + |
| 152 | +- **Documentation**: [docs/README.md](docs/README.md) |
| 153 | +- **Examples**: [examples/](examples/) |
| 154 | +- **Go Reference**: https://pkg.go.dev/github.com/vnykmshr/obcache-go |
| 155 | +- **Issues**: https://github.com/vnykmshr/obcache-go/issues |
| 156 | + |
| 157 | +## 🙏 **Acknowledgments** |
| 158 | + |
| 159 | +This library was built with production use cases in mind, incorporating lessons learned from scaling Go applications. Special thanks to the Go community for the excellent ecosystem of tools and libraries that made this possible. |
| 160 | + |
| 161 | +--- |
| 162 | + |
| 163 | +**Ready to supercharge your Go applications with intelligent caching?** |
| 164 | + |
| 165 | +```bash |
| 166 | +go get github.com/vnykmshr/obcache-go |
| 167 | +``` |
| 168 | + |
| 169 | +Happy caching! 🚀 |
0 commit comments