Skip to content

Commit

Permalink
fix: MaxRdSecond is not effective dotnetcore#550
Browse files Browse the repository at this point in the history
  • Loading branch information
Memoyu committed Sep 26, 2024
1 parent 022f9c8 commit 0c0f2f1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ private async Task<CacheValue<T>> BaseGetInternalAsync<T>(ClientSessionWrap sess
else
{
// delete expired cache
await session.Session.DeleteAsync(key, token: cancellationToken).ConfigureAwait(false);
await session.Session.DeleteAsync(GetKeySpanByte(cacheKey), token: cancellationToken).ConfigureAwait(false);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/EasyCaching.FasterKv/DefaultFasterKvCachingProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ private void BaseSetInternal<T>(ClientSessionWrap sessionWarp, string cacheKey,
if (MaxRdSecond > 0)
{
var addSec = RandomHelper.GetNext(1, MaxRdSecond);
expiration.Add(new TimeSpan(0, 0, addSec));
expiration = expiration.Add(new TimeSpan(0, 0, addSec));
}

var key = GetKeySpanByte(cacheKey);
Expand Down
2 changes: 1 addition & 1 deletion src/EasyCaching.FasterKv/EasyCaching.FasterKv.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.FASTER.Core" Version="2.1.0" />
<PackageReference Include="Microsoft.FASTER.Core" Version="2.6.5" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using EasyCaching.Core;
using EasyCaching.Core.Configurations;
using Microsoft.Extensions.DependencyInjection;
using Xunit;
using Xunit.Abstractions;
using Xunit.Sdk;

namespace EasyCaching.UnitTests.CachingTests;

Expand All @@ -15,7 +17,7 @@ public class FasterKvCachingProviderTest : BaseCachingProviderTest
public FasterKvCachingProviderTest(ITestOutputHelper testOutputHelper)
{
_testOutputHelper = testOutputHelper;
_defaultTs = TimeSpan.FromSeconds(30);
_defaultTs = TimeSpan.FromSeconds(1000);
}

protected override IEasyCachingProvider CreateCachingProvider(Action<BaseProviderOptions> additionalSetup)
Expand All @@ -42,9 +44,19 @@ protected void Set_And_Get_Big_DataSet_Should_Succeed()
_provider.Set($"Key_{i}", $"Cache_{i}", _defaultTs);
}

//_testOutputHelper.WriteLine(_provider.Get<string>($"Key_{9_9999}").Value);

for (int i = 0; i < 10_0000; i++)
{
var value = _provider.Get<string>($"Key_{i}");
var key = $"Key_{i}";

var value = _provider.Get<string>(key);

if (!value.HasValue)
{
_testOutputHelper.WriteLine(key);
}

Assert.True(value.HasValue);
Assert.Equal(value.Value, $"Cache_{i}");
}
Expand All @@ -53,17 +65,25 @@ protected void Set_And_Get_Big_DataSet_Should_Succeed()
[Fact]
protected async Task SetAsync_And_GetAsync_Big_DataSet_Should_Succeed()
{
Stopwatch stopwatch = Stopwatch.StartNew();

// set 10w key
for (int i = 0; i < 10_0000; i++)
{
await _provider.SetAsync($"Key_{i}", $"Cache_{i}", _defaultTs);
await _provider.SetAsync($"Key_Async_{i}", $"Cache_Async_{i}", _defaultTs);
}

_testOutputHelper.WriteLine(_provider.Get<string>($"Key_{9_9999}").Value ?? "空的");

for (int i = 0; i < 10_0000; i++)
{
var value = await _provider.GetAsync<string>($"Key_{i}");
{
var value = await _provider.GetAsync<string>($"Key_Async_{i}");
if (!value.HasValue)
{

}
Assert.True(value.HasValue);
Assert.Equal(value.Value, $"Cache_{i}");
Assert.Equal(value.Value, $"Cache_Async_{i}");
}
}

Expand Down

0 comments on commit 0c0f2f1

Please sign in to comment.