gowrap
gowrap copied to clipboard
Add caching template for gowrap
Add Caching Template for GoWrap
This PR adds a new caching template that automatically instruments Go interfaces with in-memory caching.
Features
- Smart Caching: Only caches methods with return values
- Error Handling: Errors are never cached, failed calls always hit the underlying implementation
-
Thread-Safe: Uses
sync.RWMutexfor concurrent access - Configurable: Customizable cache expiration and cleanup intervals
- Multi-Return Support: Handles both single and multiple return value methods
- Key Generation: Cache keys based on method name + all parameters
Usage
# Basic usage
gowrap gen -p io -i Reader -t caching -o reader_with_caching.go
# With custom decorator name
gowrap gen -p io -i Writer -t caching -v DecoratorName=CachedWriter -o writer_with_caching.go
Hey there @hexdigest , Added a caching template that instruments interfaces with in-memory caching using go-cache. Let me know if any changes needed or anything, will do the needful. Thank you.