Skip to content

Commit

Permalink
Merge pull request #46 from clevyr/use-default-sliding-expiration
Browse files Browse the repository at this point in the history
use default sliding expiration expiration if not supplied in DistributedCacheEntryOptions
  • Loading branch information
ChaosEngine authored Jun 27, 2023
2 parents f624ab0 + 160827c commit 86e202f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/Pomelo.Extensions.Caching.MySql/MySqlCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public void Set(string key, byte[] value, DistributedCacheEntryOptions options)
throw new ArgumentNullException(nameof(options));
}

//GetOptions(ref options);
GetOptions(ref options);

_dbOperations.SetCacheItem(key, value, options);

Expand Down Expand Up @@ -221,7 +221,7 @@ public async Task SetAsync(

token.ThrowIfCancellationRequested();

//GetOptions(ref options);
GetOptions(ref options);

await _dbOperations.SetCacheItemAsync(key, value, options, token);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<Version>2.1.3</Version>
<Version>2.1.4</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>Pomelo.snk</AssemblyOriginatorKeyFile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,26 +239,7 @@ await sqlServerCache.SetAsync(
// Assert
Assert.Null(value);
}

[IgnoreWhenNoSqlSetupFact]
public async Task ThrowsException_OnNoSlidingOrAbsoluteExpirationOptions()
{
// Arrange
var key = Guid.NewGuid().ToString();
var sqlServerCache = GetCache();
var expectedValue = Encoding.UTF8.GetBytes("Hello, World!");

// Act & Assert
var exception = await Assert.ThrowsAsync<InvalidOperationException>(() =>
{
return sqlServerCache.SetAsync(
key,
expectedValue,
new DistributedCacheEntryOptions());
});
Assert.Equal("Either absolute or sliding expiration needs to be provided.", exception.Message);
}


[IgnoreWhenNoSqlSetupFact]
public async Task DoesNotThrowException_WhenOnlyAbsoluteExpirationSupplied_AbsoluteExpirationRelativeToNow()
{
Expand Down Expand Up @@ -379,6 +360,24 @@ await AssertGetCacheItemFromDatabaseAsync(
absoluteExpiration: absoluteExpiration,
expectedExpirationTime: absoluteExpiration);
}

[IgnoreWhenNoSqlSetupFact]
public async Task SetCacheItem_Uses_DefaultSlidingExpiration_If_NoSlidingOrAbsoluteExpirationSupplied()
{
// Arrange
var key = Guid.NewGuid().ToString();
var sqlServerCache = GetCache();
var expectedValue = Encoding.UTF8.GetBytes("Hello, World!");

await sqlServerCache.SetAsync(
key,
expectedValue,
new DistributedCacheEntryOptions());

var cacheItem = await GetCacheItemFromDatabaseAsync(key);
Assert.NotNull(cacheItem);
Assert.Equal(cacheItem.SlidingExpirationInSeconds, _databaseOptionsFixture.Options.Value.DefaultSlidingExpiration);
}

[IgnoreWhenNoSqlSetupFact]
public async Task ExtendsExpirationTime_ForSlidingExpiration()
Expand Down Expand Up @@ -779,7 +778,8 @@ await sqlServerCache.SetAsync(
cacheItemInfo = await sqlServerCache.GetAsync(key);
Assert.Null(cacheItemInfo);
}



private MySqlCache GetCache(ISystemClock testClock = null)
{
var options = _databaseOptionsFixture.Options.Value;
Expand Down

0 comments on commit 86e202f

Please sign in to comment.