Repository navigation
Conversation
Add a caching-filter module: a filter in an intercepting-filter chain that serves a stored GET response until it expires, otherwise passes the request on and caches successful responses. Time comes from an injectable InstantSource so expiry is tested without sleeping. Includes README, PlantUML class diagram and unit tests.
PR SummaryAdds a new caching-filter module implementing the Intercepting Filter pattern. Introduces a CacheStore with TTL expiry, a CachingFilter that serves cached GET responses and stores fresh ones, and supporting components (Filter, FilterChain, Handler) plus a ProductCatalog backend. Time comes from an injectable InstantSource to enable expiry testing without sleeping. Includes README, UML diagrams, and unit tests; updates the root pom to include the module. Changes
autogenerated by presubmit.ai |
There was a problem hiding this comment.
✅ LGTM!
Review Summary
Commits Considered (1)
Add a caching-filter module: a filter in an intercepting-filter chain that serves a stored GET response until it expires, otherwise passes the request on and caches successful responses. Time comes from an injectable InstantSource so expiry is tested without sleeping. Includes README, PlantUML class diagram and unit tests.
Files Processed (18)
- caching-filter/README.md (1 hunk)
- caching-filter/etc/caching-filter.urm.png (0 hunks)
- caching-filter/etc/caching-filter.urm.puml (1 hunk)
- caching-filter/pom.xml (1 hunk)
- caching-filter/src/main/java/com/iluwatar/cachingfilter/App.java (1 hunk)
- caching-filter/src/main/java/com/iluwatar/cachingfilter/CacheStore.java (1 hunk)
- caching-filter/src/main/java/com/iluwatar/cachingfilter/CachingFilter.java (1 hunk)
- caching-filter/src/main/java/com/iluwatar/cachingfilter/Filter.java (1 hunk)
- caching-filter/src/main/java/com/iluwatar/cachingfilter/FilterChain.java (1 hunk)
- caching-filter/src/main/java/com/iluwatar/cachingfilter/Handler.java (1 hunk)
- caching-filter/src/main/java/com/iluwatar/cachingfilter/ProductCatalog.java (1 hunk)
- caching-filter/src/main/java/com/iluwatar/cachingfilter/Request.java (1 hunk)
- caching-filter/src/main/java/com/iluwatar/cachingfilter/Response.java (1 hunk)
- caching-filter/src/test/java/com/iluwatar/cachingfilter/AppTest.java (1 hunk)
- caching-filter/src/test/java/com/iluwatar/cachingfilter/CacheStoreTest.java (1 hunk)
- caching-filter/src/test/java/com/iluwatar/cachingfilter/CachingFilterTest.java (1 hunk)
- caching-filter/src/test/java/com/iluwatar/cachingfilter/FilterChainTest.java (1 hunk)
- pom.xml (1 hunk)
Actionable Comments (0)
Skipped Comments (3)
-
caching-filter/src/main/java/com/iluwatar/cachingfilter/CacheStore.java [67-78]
maintainability: "Expiry handling is correct and explicitly drops expired entries on lookup."
-
caching-filter/src/main/java/com/iluwatar/cachingfilter/CacheStore.java [91-94]
maintainability: "removePath evicts all cached entries for a given path (regardless of HTTP method)."
-
caching-filter/src/main/java/com/iluwatar/cachingfilter/CachingFilter.java [60-78]
maintainability: "Caching behavior looks correct: GETs check the cache first, miss leads to proceeding and potentially caching OK responses. Non-GETs evict the path."
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3634 +/- ##
============================================
+ Coverage 84.06% 84.15% +0.08%
- Complexity 4353 4382 +29
============================================
Files 1133 1140 +7
Lines 15400 15485 +85
Branches 739 745 +6
============================================
+ Hits 12946 13031 +85
+ Misses 2158 2155 -3
- Partials 296 299 +3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Closes #1266.
Adds the Caching Filter pattern: a filter in a request-processing chain that serves a cached response until it expires, and otherwise passes the request on and stores the response.
What is included
Filter, an immutable index-basedFilterChainand a terminalHandler, in the Intercepting Filter style.CachingFilter: on a fresh hit it answers without calling the rest of the chain; on a miss or an expired entry it proceeds and stores successful responses. Non-GET requests bypass the cache and evict the cached response for their path.CacheStore: holds the entries and the TTL expiry policy, and drops expired entries on lookup.java.time.InstantSource, so expiry is tested without sleeping.ProductCatalogcounts its lookups, soAppshows the cache saving work (5 requests, 3 back-end lookups).etc/caching-filter.urm.pumland.png), and 18 unit tests.Scope choices
Verification
./mvnw -pl caching-filter clean verify license:checkpasses.