Skip to content

Commit c8f5098

Browse files
committed
typo: Rename ExpirationMode.ImmediateExpiry => ExpirationMode.ImmediateEviction
1 parent 21acea7 commit c8f5098

File tree

5 files changed

+22
-12
lines changed

5 files changed

+22
-12
lines changed

LazyCache.UnitTests/CachingServiceMemoryCacheProviderTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ ComplexTestObject GetStuff()
870870
MemoryCacheEntryOptions GetOptions()
871871
{
872872
var options = new LazyCacheEntryOptions()
873-
.SetAbsoluteExpiration(refreshInterval, ExpirationMode.ImmediateExpiration);
873+
.SetAbsoluteExpiration(refreshInterval, ExpirationMode.ImmediateEviction);
874874
options.RegisterPostEvictionCallback((keyEvicted, value, reason, state) =>
875875
{
876876
if (reason == EvictionReason.Expired || reason == EvictionReason.TokenExpired)
@@ -900,7 +900,7 @@ public async Task GetOrAddAsyncWithImmediateExpirationDoesExpireItems()
900900
() =>
901901
{
902902
return Task.FromResult(new ComplexTestObject());
903-
}, DateTimeOffset.UtcNow.AddMilliseconds(millisecondsCacheDuration), ExpirationMode.ImmediateExpiration);
903+
}, DateTimeOffset.UtcNow.AddMilliseconds(millisecondsCacheDuration), ExpirationMode.ImmediateEviction);
904904
// trigger expiry
905905
Thread.Sleep(TimeSpan.FromMilliseconds(millisecondsCacheDuration + 50));
906906

LazyCache/AppCacheExtensions.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,8 @@ public static T GetOrAdd<T>(this IAppCache cache, string key, Func<T> addItemFac
5151
{
5252
case ExpirationMode.LazyExpiration:
5353
return cache.GetOrAdd(key, addItemFactory, new MemoryCacheEntryOptions { AbsoluteExpiration = expires });
54-
case ExpirationMode.ImmediateExpiration:
55-
return cache.GetOrAdd(key, addItemFactory, LazyCacheEntryOptions.WithImmediateAbsoluteExpiration(expires));
5654
default:
57-
throw new ArgumentOutOfRangeException(nameof(mode), mode, null);
55+
return cache.GetOrAdd(key, addItemFactory, new LazyCacheEntryOptions().SetAbsoluteExpiration(expires, mode));
5856
}
5957
}
6058

@@ -97,10 +95,8 @@ public static Task<T> GetOrAddAsync<T>(this IAppCache cache, string key, Func<Ta
9795
{
9896
case ExpirationMode.LazyExpiration:
9997
return cache.GetOrAddAsync(key, addItemFactory, new MemoryCacheEntryOptions { AbsoluteExpiration = expires });
100-
case ExpirationMode.ImmediateExpiration:
101-
return cache.GetOrAddAsync(key, addItemFactory, new LazyCacheEntryOptions().SetAbsoluteExpiration(expires,mode));
10298
default:
103-
throw new ArgumentOutOfRangeException(nameof(mode), mode, null);
99+
return cache.GetOrAddAsync(key, addItemFactory, new LazyCacheEntryOptions().SetAbsoluteExpiration(expires, mode));
104100
}
105101
}
106102

LazyCache/ExpirationMode.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
namespace LazyCache
1+
using System;
2+
using System.Diagnostics;
3+
4+
namespace LazyCache
25
{
36
public enum ExpirationMode
47
{
@@ -15,6 +18,14 @@ public enum ExpirationMode
1518
/// This will then trigger PostEvictionCallbacks at the expected time. This uses more resources
1619
/// than LazyExpiration.
1720
/// </summary>
18-
ImmediateExpiration
21+
[Obsolete("Use ExpirationMode.ImmediateEviction instead - this name is miss-leading")]
22+
ImmediateExpiration,
23+
24+
/// <summary>
25+
/// Use a timer to force eviction of expired items from the cache as soon as they expire.
26+
/// This will then trigger PostEvictionCallbacks at the expected time. This uses more resources
27+
/// than LazyExpiration.
28+
/// </summary>
29+
ImmediateEviction
1930
}
2031
}

LazyCache/Providers/MemoryCacheProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ public object GetOrCreate<T>(string key, MemoryCacheEntryOptions policy, Func<IC
3535
if(policy == null)
3636
return cache.GetOrCreate(key, factory);
3737

38-
if (!cache.TryGetValue(key, out object result))
38+
if (!cache.TryGetValue(key, out var result))
3939
{
4040
var entry = cache.CreateEntry(key);
4141
// Set the initial options before the factory is fired so that any callbacks
4242
// that need to be wired up are still added.
4343
entry.SetOptions(policy);
4444

45-
if (policy is LazyCacheEntryOptions lazyPolicy && lazyPolicy.ExpirationMode == ExpirationMode.ImmediateExpiration)
45+
if (policy is LazyCacheEntryOptions lazyPolicy && lazyPolicy.ExpirationMode != ExpirationMode.LazyExpiration)
4646
{
4747
var expiryTokenSource = new CancellationTokenSource();
4848
var expireToken = new CancellationChangeToken(expiryTokenSource.Token);

ReleaseNotes.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Release notes for LazyCache #
22

3+
## Version 2.1.3
4+
- Rename ExpirationMode.ImmediateExpiry => ExpirationMode.ImmediateEviction
5+
36
## Version 2.1.2
47
- Tweak key lock array size based on CPU count so larger for bigger machines (See PR #126 and discussion with @jjxtra)
58

0 commit comments

Comments
 (0)