Skip to content

Add DisableSlidingExpirationRefresh option to RedisCache - #66624

Open
nbk-bot wants to merge 1 commit into
dotnet:mainfrom
nbk-bot:fix/38046-redis-disable-sliding-expiration-refresh
Open

nbk-bot wants to merge 1 commit into
dotnet:mainfrom
nbk-bot:fix/38046-redis-disable-sliding-expiration-refresh

Conversation

@nbk-bot

@nbk-bot nbk-bot commented May 8, 2026 •

Copy link
Copy Markdown

Summary

Adds a new RedisCacheOptions.DisableSlidingExpirationRefresh flag. When set to true, read operations (Get, GetAsync, Refresh, RefreshAsync, and the buffered TryGet/TryGetAsync) skip the EXPIRE command that resets the sliding TTL.

This is useful when the Redis instance is temporarily in a read-only state (for example, during failover/leader election). In that situation the read itself succeeds against a replica, but the follow-up EXPIRE fails — which currently propagates as an exception and breaks reads. With the flag enabled, sessions stored in Redis can keep reading through the failover; if writes do not recover before the original TTL elapses, the key still expires naturally.

Default is false, so existing behavior is unchanged.

Fixes #38046

Changes

  • RedisCacheOptions: new public DisableSlidingExpirationRefresh property (documented).
  • RedisCache: 4 read paths guarded with && !_options.DisableSlidingExpirationRefresh.
  • PublicAPI.Unshipped.txt updated for net10.0, net11.0, net462, netstandard2.0.
  • Added one sync + one async test mirroring SlidingExpirationRenewedByAccess, asserting that with the flag enabled the key still expires on its original TTL despite repeated reads.

Test plan

  • CI build/test on all target frameworks
  • New SlidingExpirationNotRenewedWhenDisableSlidingExpirationRefreshIsTrue tests pass against a real Redis (skipped in CI like the rest of the suite)
  • Existing sliding-expiration tests still pass (default behavior unchanged)

Allows reads to skip the EXPIRE command that refreshes sliding TTL,
so reads keep working when Redis is in a read-only state (for example,
during failover/leader election).

Fixes dotnet#38046

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@nbk-bot
nbk-bot requested a review from halter73 as a code owner May 8, 2026 09:21
@github-actions github-actions Bot added the needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically label May 8, 2026
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label May 8, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Thanks for your PR, @nbk-bot. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@nbk-bot

nbk-bot commented May 8, 2026

Copy link
Copy Markdown
Author

@dotnet-policy-service agree

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime.
To make sure no conflicting changes have occurred, please rerun validation before merging. You can do this by leaving an /azp run comment here (requires commit rights), or by simply closing and reopening.

@dotnet-policy-service dotnet-policy-service Bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Sep 26, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlewares community-contribution Indicates that the PR has been added by a community member needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add configuration option to RedisCache to allow read-only access

3 participants