Skip to content

feat: add Cache Stampede Protection pattern#456

Merged
JerrettDavis merged 1 commit into
mainfrom
feat/cache-stampede-protection-449
May 30, 2026
Merged

feat: add Cache Stampede Protection pattern#456
JerrettDavis merged 1 commit into
mainfrom
feat/cache-stampede-protection-449

Conversation

@JerrettDavis

Copy link
Copy Markdown
Owner

Summary

  • adds Cache Stampede Protection as a keyed single-flight policy for suppressing duplicate cache-miss origin loads
  • adds fluent and source-generated factory paths, product catalog demo, IServiceCollection integration, docs, catalog coverage, and benchmark entries
  • adds TinyBDD coverage for runtime behavior, generator diagnostics/output, abstractions, examples, DI, and production-readiness audits

Closes #449

Verification

  • dotnet test test\PatternKit.Tests\PatternKit.Tests.csproj --configuration Release --no-restore --filter "FullyQualifiedName~CacheStampedeProtectionPolicyTests" -p:TestTfmsInParallel=false --logger "console;verbosity=minimal"
  • dotnet test test\PatternKit.Generators.Tests\PatternKit.Generators.Tests.csproj --configuration Release --no-restore --filter "FullyQualifiedNameCacheStampedeProtectionGeneratorTests|FullyQualifiedNameAbstractionsTests" -p:TestTfmsInParallel=false --logger "console;verbosity=minimal"
  • dotnet test test\PatternKit.Examples.Tests\PatternKit.Examples.Tests.csproj --configuration Release --no-restore --filter "FullyQualifiedNameCacheStampedeProtectionDemo|FullyQualifiedNameProductionReadiness|FullyQualifiedName~DependencyInjection" -p:TestTfmsInParallel=false --logger "console;verbosity=minimal"
  • dotnet format PatternKit.slnx --verify-no-changes --verbosity minimal
  • dotnet build PatternKit.slnx --configuration Release --no-restore
  • dotnet test PatternKit.slnx --configuration Release --no-build -p:TestTfmsInParallel=false --logger "console;verbosity=minimal"

Copilot AI review requested due to automatic review settings May 30, 2026 16:02
@github-actions

github-actions Bot commented May 30, 2026

Copy link
Copy Markdown
Contributor

⚠️ Deprecation Warning: The deny-licenses option is deprecated for possible removal in the next major release. For more information, see issue 997.

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds the Cache Stampede Protection pattern to PatternKit, including a core keyed single-flight policy, source-generator support, example/DI integration, tests, benchmarks, and documentation/catalog updates.

Changes:

  • Adds CacheStampedeProtectionPolicy<TResult> and generated factory support via [GenerateCacheStampedeProtection].
  • Adds product catalog demo, DI registration, benchmark routes, and TinyBDD coverage.
  • Updates catalog counts, benchmark matrices, README, docs indexes, TOCs, and pattern/generator/example docs.

Reviewed changes

Copilot reviewed 27 out of 27 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/PatternKit.Core/Cloud/CacheStampedeProtection/CacheStampedeProtectionPolicy.cs Adds the keyed single-flight runtime policy and result model.
src/PatternKit.Generators/CacheStampedeProtection/CacheStampedeProtectionGenerator.cs Adds the source generator for policy factory creation.
src/PatternKit.Generators.Abstractions/CacheStampedeProtection/CacheStampedeProtectionAttributes.cs Adds the generator attribute abstraction.
src/PatternKit.Generators/AnalyzerReleases.Unshipped.md Registers new PKCSP diagnostics.
src/PatternKit.Examples/CacheStampedeProtectionDemo/ProductCatalogStampedeProtectionDemo.cs Adds the product catalog cache stampede protection example and DI extension.
src/PatternKit.Examples/DependencyInjection/PatternKitExampleServiceCollectionExtensions.cs Adds aggregate DI registration and example record.
src/PatternKit.Examples/ProductionReadiness/PatternKitPatternCatalog.cs Adds the new catalog pattern entry.
src/PatternKit.Examples/ProductionReadiness/PatternKitExampleCatalog.cs Adds the new example catalog descriptor.
benchmarks/PatternKit.Benchmarks/Cloud/CacheStampedeProtectionBenchmarks.cs Adds construction and execution benchmark routes.
test/PatternKit.Tests/Cloud/CacheStampedeProtection/CacheStampedeProtectionPolicyTests.cs Adds runtime behavior tests for sharing, key isolation, failures, cancellation, and validation.
test/PatternKit.Generators.Tests/CacheStampedeProtectionGeneratorTests.cs Adds generator output and diagnostic tests.
test/PatternKit.Generators.Tests/AbstractionsTests.cs Adds attribute constructor and usage tests.
test/PatternKit.Examples.Tests/CacheStampedeProtectionDemo/ProductCatalogStampedeProtectionDemoTests.cs Adds example and DI integration tests.
test/PatternKit.Examples.Tests/ProductionReadiness/PatternKitPatternCatalogTests.cs Updates pattern count expectations.
test/PatternKit.Examples.Tests/ProductionReadiness/PatternKitBenchmarkCoverageTests.cs Updates benchmark route total expectation.
README.md Updates pattern totals and benchmark table entries.
docs/index.md Updates documentation landing-page pattern totals.
docs/patterns/toc.yml Adds the pattern docs TOC entry.
docs/patterns/cloud/cache-stampede-protection.md Adds pattern documentation.
docs/generators/toc.yml Adds generator docs TOC entry.
docs/generators/index.md Adds generator index entry.
docs/generators/cache-stampede-protection.md Adds generator documentation.
docs/examples/toc.yml Adds example docs TOC entry.
docs/examples/product-catalog-cache-stampede-protection.md Adds example documentation.
docs/guides/pattern-coverage.md Updates pattern coverage matrix.
docs/guides/benchmarks.md Adds benchmark placeholder rows.
docs/guides/benchmark-results.md Updates benchmark results, route totals, and generator coverage entries.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

return;
}

context.AddSource($"{type.Name}.CacheStampedeProtection.g.cs", SourceText.From(
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();
@github-actions

github-actions Bot commented May 30, 2026

Copy link
Copy Markdown
Contributor

Test Results

    12 files      12 suites   10m 41s ⏱️
 3 874 tests  3 874 ✅ 0 💤 0 ❌
12 053 runs  12 053 ✅ 0 💤 0 ❌

Results for commit 54dbaf2.

♻️ This comment has been updated with latest results.

@codecov

codecov Bot commented May 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.58333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 96.80%. Comparing base (760e26a) to head (54dbaf2).

Files with missing lines Patch % Lines
...pedeProtection/CacheStampedeProtectionGenerator.cs 98.97% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #456      +/-   ##
==========================================
+ Coverage   96.63%   96.80%   +0.17%     
==========================================
  Files         559      563       +4     
  Lines       45502    45742     +240     
  Branches     3000     6584    +3584     
==========================================
+ Hits        43969    44280     +311     
+ Misses       1533     1462      -71     
Flag Coverage Δ
unittests 96.80% <99.58%> (+0.17%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

github-actions Bot commented May 30, 2026

Copy link
Copy Markdown
Contributor

🔍 PR Validation Results

Version: ``

✅ Validation Steps

  • Build solution
  • Run tests
  • Build documentation
  • Dry-run NuGet packaging

📊 Artifacts

Dry-run artifacts have been uploaded and will be available for 7 days.


This comment was automatically generated by the PR validation workflow.

@JerrettDavis JerrettDavis force-pushed the feat/cache-stampede-protection-449 branch from 5bea174 to 54dbaf2 Compare May 30, 2026 16:21
@github-actions

Copy link
Copy Markdown
Contributor

Code Coverage

Summary
  Generated on: 05/30/2026 - 16:29:14
  Coverage date: 05/30/2026 - 16:26:41 - 05/30/2026 - 16:29:02
  Parser: MultiReport (12x Cobertura)
  Assemblies: 5
  Classes: 1653
  Files: 563
  Line coverage: 96.6%
  Covered lines: 44204
  Uncovered lines: 1538
  Coverable lines: 45742
  Total lines: 98200
  Branch coverage: 82.2% (13805 of 16774)
  Covered branches: 13805
  Total branches: 16774
  Method coverage: 96.7% (8603 of 8896)
  Full method coverage: 90.3% (8037 of 8896)
  Covered methods: 8603
  Fully covered methods: 8037
  Total methods: 8896

PatternKit.Core                                                                                                     95.5%
  PatternKit.Application.ActivityTracking.ActivityGateState                                                          100%
  PatternKit.Application.ActivityTracking.ActivityLease                                                              100%
  PatternKit.Application.ActivityTracking.ActivityRecord                                                             100%
  PatternKit.Application.ActivityTracking.ActivityTracker                                                            100%
  PatternKit.Application.Aggregates.AggregateCommandHandler<T1, T2, T3>                                              100%
  PatternKit.Application.Aggregates.AggregateCommandResult<T>                                                        100%
  PatternKit.Application.Aggregates.AggregateRoot<T1, T2>                                                            100%
  PatternKit.Application.AntiCorruption.AntiCorruptionLayer<T1, T2>                                                 90.4%
  PatternKit.Application.AntiCorruption.AntiCorruptionResult<T>                                                      100%
  PatternKit.Application.AuditLog.AuditLogAppendResult<T>                                                           85.7%
  PatternKit.Application.AuditLog.InMemoryAuditLog<T1, T2>                                                          95.4%
  PatternKit.Application.BoundedContexts.BoundedContextAdapter                                                       100%
  PatternKit.Application.BoundedContexts.BoundedContextCapability                                                   83.3%
  PatternKit.Application.BoundedContexts.BoundedContextDescriptor                                                   95.4%
  PatternKit.Application.ContextMaps.ContextMapDescriptor                                                           96.8%
  PatternKit.Application.ContextMaps.ContextMapRelationship                                                          100%
  PatternKit.Application.DataMapping.DataMapper<T1, T2>                                                             94.6%
  PatternKit.Application.DataMapping.DataMapperError                                                                  90%
  PatternKit.Application.DataMapping.DataMapperResult<T>                                                            84.6%
  PatternKit.Application.DomainEvents.DomainEventDispatcher<T>                                                      95.4%
  PatternKit.Application.DomainEvents.DomainEventDispatchResult                                                      100%
  PatternKit.Application.DomainServices.DomainServiceOperation<T1, T2>                                               100%
  PatternKit.Application.DomainServices.DomainServiceRegistry<T1, T2>                                                100%
  PatternKit.Application.EventSourcing.EventStoreAppendResult                                                        100%
  PatternKit.Application.EventSourcing.InMemoryEventStore<T1, T2>                                                   97.9%
  PatternKit.Application.EventSourcing.StoredEvent<T1, T2>                                                            80%
  PatternKit.Application.FeatureToggles.FeatureToggleDecision                                                       87.5%
  PatternKit.Application.FeatureToggles.FeatureToggleRule<T>                                                         100%
  PatternKit.Application.FeatureToggles.FeatureToggleSet<T>                                                         96.9%
  PatternKit.Application.IdentityMap.IdentityMap<T1, T2>                                                             100%
  PatternKit.Application.IdentityMap.IdentityMapResult<T>                                                           92.8%
  PatternKit.Application.ManualTaskGates.ManualTaskGate<T>                                                          98.5%
  PatternKit.Application.ManualTaskGates.ManualTaskGateState<T>                                                      100%
  PatternKit.Application.ManualTaskGates.ManualTaskRecord<T>                                                        96.9%
  PatternKit.Application.MaterializedViews.MaterializedView<T1, T2>                                                 98.4%
  PatternKit.Application.Repository.InMemoryRepository<T1, T2>                                                      92.8%
  PatternKit.Application.Repository.RepositoryResult<T>                                                             93.3%
  PatternKit.Application.ServiceLayer.ServiceLayerOperation<T1, T2>                                                 96.7%

@JerrettDavis JerrettDavis merged commit 2b11edf into main May 30, 2026
12 checks passed
@JerrettDavis JerrettDavis deleted the feat/cache-stampede-protection-449 branch May 30, 2026 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Cache Stampede Protection pattern

2 participants