Skip to content

Commit 86e202f

Browse files
authored
Merge pull request #46 from clevyr/use-default-sliding-expiration
use default sliding expiration expiration if not supplied in DistributedCacheEntryOptions
2 parents f624ab0 + 160827c commit 86e202f

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

src/Pomelo.Extensions.Caching.MySql/MySqlCache.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public void Set(string key, byte[] value, DistributedCacheEntryOptions options)
191191
throw new ArgumentNullException(nameof(options));
192192
}
193193

194-
//GetOptions(ref options);
194+
GetOptions(ref options);
195195

196196
_dbOperations.SetCacheItem(key, value, options);
197197

@@ -221,7 +221,7 @@ public async Task SetAsync(
221221

222222
token.ThrowIfCancellationRequested();
223223

224-
//GetOptions(ref options);
224+
GetOptions(ref options);
225225

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

src/Pomelo.Extensions.Caching.MySql/Pomelo.Extensions.Caching.MySql.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
1212
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
1313
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
14-
<Version>2.1.3</Version>
14+
<Version>2.1.4</Version>
1515
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
1616
<SignAssembly>true</SignAssembly>
1717
<AssemblyOriginatorKeyFile>Pomelo.snk</AssemblyOriginatorKeyFile>

test/Pomelo.Extensions.Caching.MySql.Tests/MySqlCacheWithDatabaseTest.cs

+21-21
Original file line numberDiff line numberDiff line change
@@ -239,26 +239,7 @@ await sqlServerCache.SetAsync(
239239
// Assert
240240
Assert.Null(value);
241241
}
242-
243-
[IgnoreWhenNoSqlSetupFact]
244-
public async Task ThrowsException_OnNoSlidingOrAbsoluteExpirationOptions()
245-
{
246-
// Arrange
247-
var key = Guid.NewGuid().ToString();
248-
var sqlServerCache = GetCache();
249-
var expectedValue = Encoding.UTF8.GetBytes("Hello, World!");
250-
251-
// Act & Assert
252-
var exception = await Assert.ThrowsAsync<InvalidOperationException>(() =>
253-
{
254-
return sqlServerCache.SetAsync(
255-
key,
256-
expectedValue,
257-
new DistributedCacheEntryOptions());
258-
});
259-
Assert.Equal("Either absolute or sliding expiration needs to be provided.", exception.Message);
260-
}
261-
242+
262243
[IgnoreWhenNoSqlSetupFact]
263244
public async Task DoesNotThrowException_WhenOnlyAbsoluteExpirationSupplied_AbsoluteExpirationRelativeToNow()
264245
{
@@ -379,6 +360,24 @@ await AssertGetCacheItemFromDatabaseAsync(
379360
absoluteExpiration: absoluteExpiration,
380361
expectedExpirationTime: absoluteExpiration);
381362
}
363+
364+
[IgnoreWhenNoSqlSetupFact]
365+
public async Task SetCacheItem_Uses_DefaultSlidingExpiration_If_NoSlidingOrAbsoluteExpirationSupplied()
366+
{
367+
// Arrange
368+
var key = Guid.NewGuid().ToString();
369+
var sqlServerCache = GetCache();
370+
var expectedValue = Encoding.UTF8.GetBytes("Hello, World!");
371+
372+
await sqlServerCache.SetAsync(
373+
key,
374+
expectedValue,
375+
new DistributedCacheEntryOptions());
376+
377+
var cacheItem = await GetCacheItemFromDatabaseAsync(key);
378+
Assert.NotNull(cacheItem);
379+
Assert.Equal(cacheItem.SlidingExpirationInSeconds, _databaseOptionsFixture.Options.Value.DefaultSlidingExpiration);
380+
}
382381

383382
[IgnoreWhenNoSqlSetupFact]
384383
public async Task ExtendsExpirationTime_ForSlidingExpiration()
@@ -779,7 +778,8 @@ await sqlServerCache.SetAsync(
779778
cacheItemInfo = await sqlServerCache.GetAsync(key);
780779
Assert.Null(cacheItemInfo);
781780
}
782-
781+
782+
783783
private MySqlCache GetCache(ISystemClock testClock = null)
784784
{
785785
var options = _databaseOptionsFixture.Options.Value;

0 commit comments

Comments
 (0)