-
Couldn't load subscription status.
- Fork 11
Fix cache implementation in MultiDelimiterStringSearchInterpolator and RegexBasedInterpolator #88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…nswers map when cacheAnswers is true Co-authored-by: slachiewicz <[email protected]>
…cacheAnswers is true Co-authored-by: slachiewicz <[email protected]>
|
@copilot check if this kind cache is effective in this project and usefull - go deeper how lookup is implemented - so we will not have duplicated storage |
Analyzed cache effectiveness with performance tests. Key findings: Cache IS effective and NOT duplicated storage:
The cache is valuable for real-world scenarios (Maven, build tools) where same interpolator processes many strings with same context. Recommend keeping it. |
|
@copilot make sure that cached answers will not grow too much or will be cleaned up if not needed. |
|
@copilot continue |
Cache cleanup is already properly handled - no changes needed: Automatic cleanup (default):
Manual cleanup:
Bounded growth:
Memory safety:
The implementation already ensures cache won't grow unbounded. Users have full control via the opt-in model and |
Problem
The
cacheAnswerssetting in bothMultiDelimiterStringSearchInterpolatorandRegexBasedInterpolatorhad no effect. While the code attempted to read from theexistingAnswerscache, it never populated the cache with resolved values, making the cache optimization completely ineffective.Solution
Added the missing cache population logic that stores resolved values into
existingAnswerswhencacheAnswersis enabled. This brings both interpolators in line with the implementation pattern used inStringSearchInterpolator.Code change applied to both classes:
Impact
Users who enable caching via
setCacheAnswers(true)will now see significant performance improvements when interpolating strings with repeated expressions:interpolate()callExample improvement for MultiDelimiterStringSearchInterpolator:
Example improvement for RegexBasedInterpolator:
Testing
Files Changed
MultiDelimiterStringSearchInterpolator.java: Added cache population (4 lines)MultiDelimiterStringSearchInterpolatorTest.java: Added 2 tests (58 lines)RegexBasedInterpolator.java: Added cache population (4 lines)RegexBasedInterpolatorTest.java: Added 2 tests (69 lines)Fixes #19
Original prompt
Fixes #19
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.