Description
TheTVDB recommends callers cache/proxy responses; today this client is deliberately AS IS with none. Add an opt-in caching layer via DI using our own ITvdbCache abstraction:
- If no
ITvdbCache is registered → live calls (current behaviour).
- If one is registered → cache-call (serve from cache, else fetch + store).
Pattern (the clean way)
Null Object + a caching DelegatingHandler — DI-native, composes with the existing auth (and envelope-unwrap) handlers in the HttpClient pipeline:
ITvdbCache (in TvdbClient.Abstractions) — TryGetAsync(key) / SetAsync(key, value, ttl).
NoOpTvdbCache — pass-through; registered by AddTvdbClient via TryAddSingleton<ITvdbCache, NoOpTvdbCache>() so a consumer-registered implementation wins.
CachingHandler : DelegatingHandler — keys on request method+URI; on GET, serves a cached response or forwards + stores. No-op cache ⇒ effectively transparent.
Consumer usage:
services.AddSingleton<ITvdbCache, MyRedisTvdbCache>(); // opt in
services.AddTvdbClient(config); // no-op stays if the above is absent
Notes / open questions
- Cache key + TTL policy (per-endpoint? honor any Cache-Control TheTVDB sends?).
- HTTP-level (handler, caches the raw enveloped body — simplest) vs typed-level (caches deserialized DTOs).
- Ship as part of the core, or a separate
TvdbClient.Caching package with in-memory + a sample distributed impl.
🤖 Generated with Claude Code
Description
TheTVDB recommends callers cache/proxy responses; today this client is deliberately
AS ISwith none. Add an opt-in caching layer via DI using our ownITvdbCacheabstraction:ITvdbCacheis registered → live calls (current behaviour).Pattern (the clean way)
Null Object + a caching
DelegatingHandler— DI-native, composes with the existing auth (and envelope-unwrap) handlers in the HttpClient pipeline:ITvdbCache(inTvdbClient.Abstractions) —TryGetAsync(key)/SetAsync(key, value, ttl).NoOpTvdbCache— pass-through; registered byAddTvdbClientviaTryAddSingleton<ITvdbCache, NoOpTvdbCache>()so a consumer-registered implementation wins.CachingHandler : DelegatingHandler— keys on request method+URI; on GET, serves a cached response or forwards + stores. No-op cache ⇒ effectively transparent.Consumer usage:
Notes / open questions
TvdbClient.Cachingpackage with in-memory + a sample distributed impl.🤖 Generated with Claude Code