feat: add Cache-Aside pattern#243
Conversation
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Code Coverage |
Test Results 1 files 1 suites 2m 26s ⏱️ Results for commit 57aaddb. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #243 +/- ##
==========================================
+ Coverage 91.27% 96.34% +5.06%
==========================================
Files 288 292 +4
Lines 27281 27584 +303
Branches 3798 3845 +47
==========================================
+ Hits 24902 26577 +1675
+ Misses 1053 1007 -46
+ Partials 1326 0 -1326
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
🔍 PR Validation ResultsVersion: `` ✅ Validation Steps
📊 ArtifactsDry-run artifacts have been uploaded and will be available for 7 days. This comment was automatically generated by the PR validation workflow. |
There was a problem hiding this comment.
Pull request overview
Adds a first-class Cache-Aside pattern slice to PatternKit, including a runtime CacheAsidePolicy<TResult> implementation, a Roslyn source generator + attributes to produce policy factories, and a product catalog example demonstrating fluent vs generated usage with DI wiring.
Changes:
- Introduces
CacheAsidePolicy<TResult>(runtime) with hit/miss results, TTL, cache predicates, invalidation, and async loading. - Adds Cache-Aside generator attributes, incremental generator implementation, diagnostics, and generator tests/coverage.
- Adds product catalog cache-aside example (docs + DI registration + tests) and registers Cache-Aside in the pattern/example catalogs.
Reviewed changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| test/PatternKit.Tests/Cloud/CacheAside/CacheAsidePolicyTests.cs | Adds runtime behavior tests for hit/miss, TTL, predicates, invalidation, cancellation, and config validation. |
| test/PatternKit.Generators.Tests/CacheAsidePolicyGeneratorTests.cs | Adds generator tests for factory generation and diagnostics. |
| test/PatternKit.Generators.Tests/AbstractionsAttributeCoverageTests.cs | Extends attribute coverage tests to include new Cache-Aside abstractions. |
| test/PatternKit.Examples.Tests/ProductionReadiness/PatternKitPatternCatalogTests.cs | Updates catalog expectations to include Cache-Aside. |
| test/PatternKit.Examples.Tests/DependencyInjection/PatternKitExampleDependencyInjectionTests.cs | Adds DI smoke-coverage for the Cache-Aside example. |
| test/PatternKit.Examples.Tests/CacheAsideDemo/ProductCatalogCacheAsideDemoTests.cs | Adds TinyBDD tests for the product catalog cache-aside example (fluent + generated + DI). |
| src/PatternKit.Generators/CacheAside/CacheAsidePolicyGenerator.cs | Implements Cache-Aside incremental source generator and diagnostics. |
| src/PatternKit.Generators/AnalyzerReleases.Unshipped.md | Registers new PKCA diagnostics in analyzer release notes. |
| src/PatternKit.Generators.Abstractions/CacheAside/CacheAsideAttributes.cs | Adds [GenerateCacheAsidePolicy] and [CacheAsidePredicate] attributes. |
| src/PatternKit.Examples/ProductionReadiness/PatternKitPatternCatalog.cs | Registers Cache-Aside pattern entry and its docs/tests/source links. |
| src/PatternKit.Examples/ProductionReadiness/PatternKitExampleCatalog.cs | Registers “Product Catalog Cache-Aside” example descriptor. |
| src/PatternKit.Examples/DependencyInjection/PatternKitExampleServiceCollectionExtensions.cs | Adds DI registration for the new Cache-Aside example integration. |
| src/PatternKit.Examples/CacheAsideDemo/ProductCatalogCacheAsideDemo.cs | Adds the product catalog read-model example + fluent/generated policies + IServiceCollection wiring. |
| src/PatternKit.Core/Cloud/CacheAside/CacheAsidePolicy.cs | Adds Cache-Aside runtime policy, result model, store abstraction, and in-memory store. |
| docs/patterns/toc.yml | Adds Cache-Aside to docs navigation. |
| docs/patterns/cloud/cache-aside.md | Adds Cache-Aside pattern documentation and usage guidance. |
| docs/guides/pattern-coverage.md | Adds Cache-Aside to pattern coverage matrix. |
| docs/generators/toc.yml | Adds Cache-Aside generator to docs navigation. |
| docs/generators/index.md | Adds Cache-Aside generator to generator index and quick reference. |
| docs/generators/cache-aside.md | Adds Cache-Aside generator documentation and rules/diagnostics. |
| docs/examples/toc.yml | Adds product catalog cache-aside example to examples navigation. |
| docs/examples/product-catalog-cache-aside.md | Adds documentation for the product catalog cache-aside example. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
|
|
||
| public Builder WithTimeToLive(TimeSpan ttl) | ||
| { |
| sb.Append(GetAccessibility(type.DeclaredAccessibility)).Append(' '); | ||
| if (type.IsStatic) | ||
| sb.Append("static "); | ||
| else if (type.IsAbstract && type.TypeKind == TypeKind.Class) | ||
| sb.Append("abstract "); | ||
| else if (type.IsSealed && type.TypeKind == TypeKind.Class) | ||
| sb.Append("sealed "); | ||
| sb.Append("partial ").Append(type.TypeKind == TypeKind.Struct ? "struct" : "class").Append(' ').Append(type.Name).AppendLine(); | ||
| sb.AppendLine("{"); |
Summary
Closes #230
Local validation
Note: local full example/generator test builds still hit the known SDK/Roslyn compiler-version mismatch that prevents source generators from running locally; CI remains authoritative for those surfaces.