Skip to content

feat: opt-in KV bucket auto-creation + bucket configuration #38

Description

@matthewdevenny

Problem

Consumers must pre-create the KV bucket with LimitMarkerTTL before using the cache (it's the most prominent step in the README). NatsCache calls INatsKVContext.GetStoreAsync (src/NatsDistributedCache/NatsCache.cs), which throws if the bucket doesn't exist.

Investigation

INatsKVContext exposes CreateOrUpdateStoreAsync / CreateStoreAsync / UpdateStoreAsync. NatsKVConfig exposes: LimitMarkerTTL, History, Storage, NumberOfReplicas, MaxBytes, MaxValueSize, Compression, MaxAge, Description, Placement, ….

Proposal

Add opt-in bucket auto-creation:

  • NatsCacheOptions.CreateBucketIfNotExists (default false — no surprise infra changes).
  • A bucket-config hook (Action<NatsKVConfig> or typed sub-options) to set storage/replicas/limits.
  • When enabled, call CreateOrUpdateStoreAsync with cache-appropriate defaults:
    • LimitMarkerTTL set (required for per-key TTL).
    • History = 1 (the existing PutWithTtl remarks require it for correct TTL behavior).

Acceptance criteria

  • With the flag enabled, a missing bucket is created with LimitMarkerTTL + History = 1.
  • Disabled by default; existing behavior unchanged.
  • The README's manual CreateOrUpdateStoreAsync step becomes optional.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    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