dotnet/aspnetcore

Add configuration option to `RedisCache` to allow read-only access

Open

#38,046 创建于 2021年11月3日

在 GitHub 查看
 (2 评论) (2 反应) (0 负责人)C# (10,653 fork)batch import
area-middlewarefeature-cachinghelp wanted

仓库指标

Star
 (37,933 star)
PR 合并指标
 (平均合并 16天 9小时) (30 天内合并 258 个 PR)

描述

Currently, RedisCache resets expiry for keys on every read (https://github.com/dotnet/aspnetcore/blob/main/src/Caching/StackExchangeRedis/src/RedisCache.cs#L293 and in the async version as well).

When using Redis as a session storage, this can lead to sessions getting invalidated unnecessarily on Redis failover. During a new leader election read-only access is preserved which would allow existing clients to continue. However due to the EXPIRE command being issued alongside the read, the read command will fail.

This might be desired behaviour in other circumstances. For a session storage solution it would be fine to just ignore the exception on expire and carry on. In the case that Redis writes do not become available within expiry time, the session would then expire. It would also still expire when attempting other writes.

A configuration option for the cache would be nice to allow expire to fail. Otherwise, changing the variables in the class to protected so sensible overrides are possible might be another solution.

贡献者指南