Cache-Aside Generator
The cache-aside generator creates a strongly typed CacheAsidePolicy<TResult> factory from declarative attributes. It is useful when cache TTLs and cacheability rules should live beside the read model contract while still producing the same runtime policy as the fluent API.
[GenerateCacheAsidePolicy(
typeof(ProductReadModel),
FactoryMethodName = "CreateGeneratedPolicy",
PolicyName = "product-catalog",
TimeToLiveMilliseconds = 300000)]
public static partial class ProductCatalogCacheAsidePolicy
{
[CacheAsidePredicate]
private static bool ShouldCache(ProductReadModel product)
=> product.Active;
}
The generated factory returns PatternKit.Cloud.CacheAside.CacheAsidePolicy<ProductReadModel> and applies the optional cache predicate.
Rules
- The host type must be
partial. TimeToLiveMillisecondsmust be non-negative.- A value of
0means no expiration. - Cache predicates must be
static boolmethods with oneTResultparameter. - Only one cache predicate can be declared.
Diagnostics use the PKCA prefix.