From 1776f6d63455bb208105d08f3b8e85700be3354a Mon Sep 17 00:00:00 2001 From: Cosmin Staicu Date: Thu, 10 Sep 2026 17:53:33 +0300 Subject: [PATCH] refactor(cache): make the size provider a field, since that is what it is SizeProvider was a get-only private property holding a value resolved once from the options. That is a readonly field wearing a property's clothes: no computation, no interception, nothing a property buys. It now sits with the other fields as _sizeProvider, which also keeps it out of the property block that the ordering rules group. The three other private properties in the library stay as they are: Database, ContinueLoop and ConnectionMultiplexer all compute on each read, which is what a private property is for. IMemoryCacheOptions.SizeProvider, the public option this reads from, is untouched. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01NsPw6MZHPGmpbo6WDuLzF1 Signed-off-by: Cosmin Staicu --- src/UiPath.Caching/MemoryCacheSetter.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/UiPath.Caching/MemoryCacheSetter.cs b/src/UiPath.Caching/MemoryCacheSetter.cs index 90d649bc..6e8b359a 100644 --- a/src/UiPath.Caching/MemoryCacheSetter.cs +++ b/src/UiPath.Caching/MemoryCacheSetter.cs @@ -16,14 +16,13 @@ internal abstract class MemoryCacheSetter( ) { private readonly KeyMasker _masker = masker ?? KeyMasker.Off; + private readonly ICacheEntrySizeProvider _sizeProvider = memoryCacheOptions.SizeProvider ?? new DefaultCacheEntrySizeProvider(); private const string EventRefreshMetadataFailed = "Caching." + nameof(MemoryCacheSetter) + "." + nameof(RefreshMetadata) + ".Failed"; private const string PropCacheKey = "CacheKey"; private const string PropTopicKey = "TopicKey"; private const string PropTransportId = "TransportId"; - private ICacheEntrySizeProvider SizeProvider { get; } = memoryCacheOptions.SizeProvider ?? new DefaultCacheEntrySizeProvider(); - protected TimeProvider Clock { get; } = clock; public bool Set(ICacheEntryOptions options, ICacheEntry item, Type entryType, TimeSpan? maxExpiration) @@ -43,7 +42,7 @@ public bool Set(ICacheEntryOptions options, ICacheEntry item, Type entryType, Ti memOptions.RegisterPostEvictionCallback(PostEviction, token); if(memoryCacheOptions.SizeLimit.HasValue) { - memOptions.SetSize(SizeProvider.GetSize(item)); + memOptions.SetSize(_sizeProvider.GetSize(item)); } memoryCache.Set(options.CacheKey, item, memOptions); return true;