dotnet-cqrs/docs/event-streaming/retention-policies/wildcard-policies.md

1.4 KiB

Wildcard Policies

Set default retention policies for all streams using wildcard ("*") pattern.

Overview

Wildcard policies provide a default retention configuration that applies to all streams unless overridden by stream-specific policies.

Configuration

// Default policy for all streams
var defaultPolicy = new RetentionPolicyConfig
{
    StreamName = "*",  // Wildcard applies to all streams
    MaxAge = TimeSpan.FromDays(365),
    Enabled = true
};

await _policyStore.SetPolicyAsync(defaultPolicy);

Policy Resolution

Stream-specific policies override wildcard:

Priority (highest to lowest):
1. Stream-specific policy (e.g., "orders")
2. Wildcard policy ("*")
3. No retention (keep forever)

Example

// Set default for all streams: 90 days
await _policyStore.SetPolicyAsync(new RetentionPolicyConfig
{
    StreamName = "*",
    MaxAge = TimeSpan.FromDays(90),
    Enabled = true
});

// Override for audit logs: 7 years
await _policyStore.SetPolicyAsync(new RetentionPolicyConfig
{
    StreamName = "audit-logs",
    MaxAge = TimeSpan.FromDays(365 * 7),
    Enabled = true
});

// Result:
// - "audit-logs": 7 years
// - "orders": 90 days (default)
// - "analytics": 90 days (default)
// - all other streams: 90 days (default)

See Also