Skip to content

feat: configurable fail-open behavior on NATS faults #41

Description

@matthewdevenny

Problem

When NATS is unavailable, reads and writes throw (src/NatsDistributedCache/NatsCache.csGetAndRefreshAsync rethrows; the lazy KV-store initializer rethrows on failure). For direct IDistributedCache consumers, a transient NATS blip can cascade into an application outage.

Investigation

HybridCache tends to handle L2 (distributed) failures gracefully, so under HybridCache this is partially absorbed. This option primarily protects direct IDistributedCache consumers and makes the failure behavior explicit and configurable.

Proposal

Add NatsCacheOptions.FailureMode (e.g. Throw (default) | FailOpen):

  • FailOpen on read → log + return a cache miss.
  • FailOpen on write → log + swallow.
  • Throw keeps the current behavior (default, non-breaking).

Acceptance criteria

  • With FailOpen, a simulated NATS outage yields cache misses + logs instead of exceptions.
  • Default (Throw) behavior is unchanged.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions