Skip to content

[PM-42157] fix: register separate memory caches for icons and change-password URIs - #8226

Open
deniswe wants to merge 1 commit into
bitwarden:mainfrom
deniswe:fix/icons-separate-memory-caches
Open

[PM-42157] fix: register separate memory caches for icons and change-password URIs#8226
deniswe wants to merge 1 commit into
bitwarden:mainfrom
deniswe:fix/icons-separate-memory-caches

Conversation

@deniswe

@deniswe deniswe commented Aug 18, 2026

Copy link
Copy Markdown

AddMemoryCache registers IMemoryCache with TryAdd, so calling it twice created one shared cache rather than two. The second options callback also won, silently discarding IconsSettings.CacheSizeLimit. Register each cache as its own keyed singleton so both honour their configured size limits independently.

Fixes #7701

🎟️ Tracking

#7701 (PM-37996)
#7701

📔 Objective

Startup.ConfigureServices called services.AddMemoryCache(...) twice, intending one cache for
IconsController and one for ChangePasswordUriController. Because AddMemoryCache registers
IMemoryCache via TryAdd, the second call registers no second cache — it only appends another
options callback. Both controllers therefore shared a single cache whose SizeLimit came from
whichever value was configured last (ChangePasswordUriSettings.CacheSizeLimit), silently
discarding IconsSettings.CacheSizeLimit. Cached icons were then evicted under a size budget
never intended for them, matching the reported symptom of icons disappearing.

This registers the two caches as separate keyed singletons, so each honours its own configured
CacheSizeLimit and neither evicts the other's entries. Keyed registration follows the existing
pattern in the codebase (e.g. [FromKeyedServices(OrganizationReportCacheConstants.CacheName)]).

The registration moved into an AddCaches extension method alongside the existing
ConfigureHttpClients / AddHtmlParsing / AddServices, which also makes it directly testable.
Added tests cover that the two caches are distinct instances, do not share entries, and each
applies its own size limit.

Note for reviewers: deployments that configured only IconsSettings.CacheSizeLimit
previously ended up with no effective limit at all; that limit now takes effect, so their icon
cache will begin evicting. The default configuration (null for both) is unchanged.

AddMemoryCache registers IMemoryCache with TryAdd, so calling it twice created one
shared cache rather than two. The second options callback also won, silently discarding
IconsSettings.CacheSizeLimit. Register each cache as its own keyed singleton so both honour
their configured size limits independently.

Fixes bitwarden#7701
@bitwarden-bot

Copy link
Copy Markdown
Collaborator

Thank you for your contribution! We've added this to our internal Community PR board for review.
ID: PM-42157
Link: https://bitwarden.atlassian.net/browse/PM-42157

Details on our contribution process can be found here: https://contributing.bitwarden.com/contributing/pull-requests/community-pr-process.

@bitwarden-bot bitwarden-bot changed the title fix: register separate memory caches for icons and change-password URIs [PM-42157] fix: register separate memory caches for icons and change-password URIs Aug 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Icon Cache Invalidated By Change Password URL Cache?

2 participants