Fix cache implementation in MultiDelimiterStringSearchInterpolator and RegexBasedInterpolator #88
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The
cacheAnswers
setting in bothMultiDelimiterStringSearchInterpolator
andRegexBasedInterpolator
had no effect. While the code attempted to read from theexistingAnswers
cache, 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
existingAnswers
whencacheAnswers
is 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.