Skip to content

Commit 3d57918

Browse files
committed
test: add unit tests for local cache behavior without Redis in HybridCacheTests
1 parent 2e24d32 commit 3d57918

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

src/HybridRedisCache.Test/HybridCacheTests.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1731,4 +1731,52 @@ async Task<int> Lockey(string locKey, int millisecondsDelay)
17311731
}
17321732
}
17331733
}
1734+
1735+
[Fact]
1736+
public async Task Cache_On_Local_Without_Redis_Set_Option_Test()
1737+
{
1738+
// Arrange
1739+
var key1 = UniqueKey;
1740+
var value1 = "value1";
1741+
1742+
await Cache.SetAsync(key1, value1,
1743+
TimeSpan.FromMilliseconds(100),
1744+
TimeSpan.FromMinutes(10),
1745+
redisCacheEnable: false); // without redis caching
1746+
1747+
// Act
1748+
var fetchedValue = await Cache.GetAsync<string>(key1);
1749+
await Task.Delay(100);
1750+
var fetchedNullValue = await Cache.GetAsync<string>(key1);
1751+
1752+
// Assert
1753+
Assert.Equal(value1, fetchedValue);
1754+
Assert.Null(fetchedNullValue); // read from redis, but also redis has been expired
1755+
}
1756+
1757+
[Fact]
1758+
public async Task Cache_On_Local_Without_Redis_Set_Entry_Test()
1759+
{
1760+
// Arrange
1761+
var key1 = UniqueKey;
1762+
var value1 = "value1";
1763+
1764+
await Cache.SetAsync(key1, value1, new HybridCacheEntry
1765+
{
1766+
FireAndForget = false,
1767+
LocalCacheEnable = true,
1768+
RedisCacheEnable = false, // without redis caching
1769+
RedisExpiry = TimeSpan.FromMinutes(1),
1770+
LocalExpiry = TimeSpan.FromMilliseconds(100)
1771+
});
1772+
1773+
// Act
1774+
var fetchedValue = await Cache.GetAsync<string>(key1);
1775+
await Task.Delay(100);
1776+
var fetchedNullValue = await Cache.GetAsync<string>(key1);
1777+
1778+
// Assert
1779+
Assert.Equal(value1, fetchedValue);
1780+
Assert.Null(fetchedNullValue); // read from redis, but also redis has been expired
1781+
}
17341782
}

0 commit comments

Comments
 (0)