Skip to content

Conversation

@retr0-kernel
Copy link

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.RWMutex for 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

- Add templates/caching with in-memory caching using go-cache
- Cache successful method results based on method name + parameters
- Skip caching for void methods and error results
- Thread-safe implementation with configurable expiration
- Comprehensive test coverage for all caching scenarios
- Follows existing gowrap template patterns and conventions
@retr0-kernel
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant