Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/CacheManager.Core/BaseCacheManager.GetOrAdd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ private bool TryGetOrAddInternal(string key, string region, Func<string, string,
var tries = 0;
do
{
tries++;
item = GetCacheItemInternal(key, region);
if (item != null)
{
Expand All @@ -155,7 +154,7 @@ private bool TryGetOrAddInternal(string key, string region, Func<string, string,
}
}
}
while (tries <= Configuration.MaxRetries);
while (++tries < Configuration.MaxRetries);

return false;
}
Expand All @@ -166,7 +165,6 @@ private CacheItem<TCacheValue> GetOrAddInternal(string key, string region, Func<
var tries = 0;
do
{
tries++;
var item = GetCacheItemInternal(key, region);
if (item != null)
{
Expand All @@ -193,7 +191,7 @@ private CacheItem<TCacheValue> GetOrAddInternal(string key, string region, Func<
}
}
}
while (tries <= Configuration.MaxRetries);
while (++tries < Configuration.MaxRetries);

// should usually never occur, but could if e.g. max retries is 1 and an item gets added between the get and add.
// pretty unusual, so keep the max tries at least around 50
Expand Down
4 changes: 1 addition & 3 deletions src/CacheManager.Core/BaseCacheManager.Update.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ private TCacheValue AddOrUpdateInternal(CacheItem<TCacheValue> item, Func<TCache
var tries = 0;
do
{
tries++;

if (AddInternal(item))
{
if (_logTrace)
Expand Down Expand Up @@ -94,7 +92,7 @@ private TCacheValue AddOrUpdateInternal(CacheItem<TCacheValue> item, Func<TCache
Configuration.MaxRetries);
}
}
while (tries <= maxRetries);
while (++tries < maxRetries);

// exceeded max retries, failing the operation... (should not happen in 99,99% of the cases though, better throw?)
throw new InvalidOperationException(
Expand Down
2 changes: 1 addition & 1 deletion src/CacheManager.StackExchange.Redis/RedisCacheHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public override UpdateItemResult<TCacheValue> Update(string key, string region,

Logger.LogDebug("Update of {0} {1} failed with version conflict, retrying {2}/{3}", key, region, tries, maxRetries);
}
while (tries <= maxRetries);
while (tries < maxRetries);

return UpdateItemResult.ForTooManyRetries<TCacheValue>(tries);
});
Expand Down