Skip to content

feat(cache): serve stale values to plain reads that allow them - #591

Merged
cosmin-staicu merged 1 commit into
mainfrom
feat/fail-safe-stale-reads
Nov 30, 2026
Merged

cosmin-staicu merged 1 commit into
mainfrom
feat/fail-safe-stale-reads

Conversation

@cosmin-staicu

Copy link
Copy Markdown
Member

Summary

A new policy option, FailSafeAllowStaleReads, lets single-key GetAsync and GetCacheEntryAsync return an expired value. Stacked on #587; this PR shows only its own layer.

Changes

  • GetCacheEntryAsync marks a stale entry with the new ICacheEntry.IsStale member. It is a default member that returns false, so existing implementers do not break.
  • InMemory returns the node's kept value once its deadline has passed. A value the local tier evicted early is not stale before its deadline.
  • Redis-only and layered caches return the expired copy that a read-only transaction on the master confirmed. It is bounded by the writer's window and by the caller's own stale age on the monotonic clock.
  • A layered cache serves it only when it hears peer events and shares the Redis tier's TimeProvider. If a peer change or lost events are heard while a shared read runs, no caller of that read gets the copy.
  • Callers without the option get no confirm read and no extra allocation. Allocation pins cover the plain paths.
  • Validation refuses the option without FailSafeEnabled, and without FailSafeDistributedEnabled on a provider with a Redis tier. A named policy that turns fail-safe off may inherit the option but may not set it. A zero FailSafeMaxStaleAge is refused when it would set the Redis window.
  • Stale hits are counted per source. The resilience guide, settings reference, interfaces, glossary and CHANGELOG describe the option, its read cost and its limits.

Tests

Release, net10.0 and net8.0, with Redis 7.4 and 6.2: stale-read InMemory, Redis-only and layered tests, peer and validation tests, fail-safe classes, allocation pins (no pinned constant changed), PluginContract and Config.

@github-actions github-actions Bot added the needs-cla-review A maintainer should assess whether a signed CLA is required (see CONTRIBUTING.md) label Nov 30, 2026
@github-actions

Copy link
Copy Markdown

🔎 Maintainer heads-up: automated triage flagged this PR as potentially material, so it may need a signed CLA in addition to the DCO sign-off.

Strong signals

  • adds public API surface (PublicAPI.Unshipped.txt in src/UiPath.Caching.Abstractions)

Other signals

  • large production change (+423 lines under src/)

This is advisory only — the bot does not decide. Please judge against the CLA criteria (material, product-critical, patent-sensitive, corporate contributor, broad commercial use). Note that thresholds can be gamed by splitting PRs, so use your judgement.

  • If a CLA is needed → add the cla-required label (a contributor comment with signing steps is posted automatically).
  • If it is not needed → replace needs-cla-review with cla-not-required so later pushes don't re-flag it.

@cosmin-staicu
cosmin-staicu added this pull request to stack #590 November 30, 2026 15:48
@cosmin-staicu
cosmin-staicu force-pushed the feat/fail-safe-stale-reads branch from a6a60ca to 3fb0025 Compare November 30, 2026 15:50
@cosmin-staicu cosmin-staicu added cla-not-required Maintainer reviewed: no CLA required for this contribution and removed needs-cla-review A maintainer should assess whether a signed CLA is required (see CONTRIBUTING.md) labels Nov 30, 2026
Base automatically changed from feat/fail-safe-redis-only to main November 30, 2026 16:10
@cosmin-staicu
cosmin-staicu force-pushed the feat/fail-safe-stale-reads branch from 3fb0025 to a28d645 Compare November 30, 2026 16:10
A new policy option, FailSafeAllowStaleReads, lets single-key GetAsync and
GetCacheEntryAsync return an expired value. GetCacheEntryAsync marks such an
entry with the new ICacheEntry.IsStale member, which defaults to false.

On InMemory the read returns the node's kept value once its deadline has
passed. A value the local tier evicted early is not stale before its deadline.

On Redis-only and layered caches the read returns the expired copy that a
read-only transaction on the master confirmed, within the writer's window and
the caller's own stale age on the monotonic clock. A layered cache serves it
only when it hears peer events and shares the Redis tier's TimeProvider.
Inner single-key reads, the opt-in stale copy read included, never carry the
option. When a peer change or lost events are heard while a shared read runs,
no caller of that read gets the copy. Callers without the option get no
confirm read and no extra allocation.

Validation refuses the option without FailSafeEnabled, and without
FailSafeDistributedEnabled on a provider with a Redis tier. A named policy
that turns fail-safe off may inherit the option, but may not set it. A zero
FailSafeMaxStaleAge is refused when it would set the Redis window, that is
with FailSafeDistributedEnabled on and FailSafeDistributedMaxStaleAge unset.

Stale hits are counted per source, and the guide, settings reference and
changelog describe the option, its read cost and its limits.

Signed-off-by: Cosmin Staicu <cosmin.staicu@uipath.com>
@cosmin-staicu
cosmin-staicu force-pushed the feat/fail-safe-stale-reads branch from a28d645 to 315bb92 Compare November 30, 2026 16:24
@sonarqubecloud

Copy link
Copy Markdown

@cosmin-staicu
cosmin-staicu merged commit c868d91 into main Nov 30, 2026
21 of 22 checks passed
@cosmin-staicu
cosmin-staicu deleted the feat/fail-safe-stale-reads branch November 30, 2026 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-not-required Maintainer reviewed: no CLA required for this contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant