Path: redb-route/redb.Route.Cache/CacheEndpointOptions.cs Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.Cache/CacheEndpointOptions.cs ---- using redb.Route.Core; namespace redb.Route.Cache; /// /// Options of a cache: endpoint: /// cache:<region>?action=get|put|remove|clear&key=${header.id}&ttl=5m&sliding=1m&provider=memory|distributed&headers=X-Rate,Content-Language. /// public sealed class CacheEndpointOptions : EndpointOptions { /// get (default), put, remove or clear. public string Action { get; set; } = "get"; /// Entry key; ${...} resolved per message. Required except for clear. public DynamicValue? Key { get; set; } /// Absolute lifetime for put (5m, 30s, hh:mm:ss). public string? Ttl { get; set; } /// Sliding lifetime for put. public string? Sliding { get; set; } /// memory (default) or distributed. public string? Provider { get; set; } /// /// put only: the headers stored with the body, by name, comma-separated. A put sees the /// message as a whole and cannot tell the headers of the value from the headers of the request, so /// it stores none unless named; a credential (Authorization, Cookie, …) cannot be named. /// public string? Headers { get; set; } /// Parsed action. public CacheAction ParsedAction => Action.ToLowerInvariant() switch { "get" => CacheAction.Get, "put" => CacheAction.Put, "remove" => CacheAction.Remove, "clear" => CacheAction.Clear, _ => throw new ArgumentException($"Cache endpoint: unknown action '{Action}' (get, put, remove, clear)."), }; /// Parsed provider; null = package default. public CacheProvider? ParsedProvider => Provider?.ToLowerInvariant() switch { null or "" => null, "memory" => CacheProvider.Memory, "distributed" => CacheProvider.Distributed, _ => throw new ArgumentException($"Cache endpoint: unknown provider '{Provider}' (memory, distributed)."), }; /// The header names of ; null when none were given. public IReadOnlyCollection? ParsedHeaders { get { if (string.IsNullOrWhiteSpace(Headers)) return null; var names = Headers.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); if (names.Length == 0) throw new ArgumentException("Cache endpoint: headers= names no header."); foreach (var name in names) if (CacheHeaderPolicy.IsCredential(name)) throw new ArgumentException($"Cache endpoint: '{name}' is a credential and cannot be cached: a hit would hand it to another exchange."); return names; } } /// public override void Validate() { _ = ParsedAction; _ = ParsedProvider; _ = CacheDuration.Parse(Ttl); _ = CacheDuration.Parse(Sliding); if (ParsedAction != CacheAction.Clear && Key is null) throw new ArgumentException($"Cache endpoint: action '{Action}' needs key=..."); if (ParsedHeaders is not null && ParsedAction != CacheAction.Put) throw new ArgumentException($"Cache endpoint: headers= belongs to action=put; action '{Action}' takes the entry as it was stored."); } /// protected override string? UnknownParameterHint(string name) => string.Equals(name, "cacheHeaders", StringComparison.OrdinalIgnoreCase) ? "A put stores no headers unless they are named: headers=X-Rate,Content-Language. It cannot tell the headers of the value from the headers of the request, and a hit hands what it stores to another exchange." : null; } /// Operations of the cache: component. public enum CacheAction { /// Read the entry into the message, or into Out when it was cached as a reply; sets cache.hit. Get, /// Store the message under the key. Put, /// Remove the key. Remove, /// Remove every key of the region. Clear, }