You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: AsyncMemoryCache/AsyncMemoryCache.cs
+48-1Lines changed: 48 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,5 @@
1
-
usingMicrosoft.Extensions.Logging;
1
+
usingAsyncMemoryCache.EvictionBehaviors;
2
+
usingMicrosoft.Extensions.Logging;
2
3
usingMicrosoft.Extensions.Logging.Abstractions;
3
4
usingNito.AsyncEx;
4
5
usingSystem;
@@ -10,16 +11,58 @@
10
11
11
12
namespaceAsyncMemoryCache;
12
13
14
+
/// <summary>
15
+
/// This interface exists mainly to avoid having concrete types as constructor arguments.
16
+
/// An effect of this is enabling subsitution and as a result, easier testing, where an actual concrete instance is not required in each and every test that uses a class that looks like the following
17
+
/// <para/>
18
+
/// <code>
19
+
/// public MyService(AsyncMemoryCache<string, SomeCacheable>) { }
20
+
/// </code>
21
+
/// </summary>
22
+
/// <typeparam name="TKey">The type of the key for cache items represented by the cache.</typeparam>
23
+
/// <typeparam name="TValue">The type of the value which each item in the cache will hold.</typeparam>
13
24
publicinterfaceIAsyncMemoryCache<TKey,TValue>
14
25
whereTKey:notnull
15
26
whereTValue:IAsyncDisposable
16
27
{
28
+
/// <summary>
29
+
/// Gets the cached item with the specified key.
30
+
/// </summary>
31
+
/// <param name="key">The key of the element to get.</param>
32
+
/// <returns>A <see cref="CacheEntityReference{TKey, TValue}"/> representing the lifetime of the underlying <see cref="CacheEntity{TKey, TValue}"/> until disposed.</returns>
/// Gets the value associated with this key if it exists, or generates a new entry using the provided key and a value from the given factory if the key is not found.<br/>
37
+
/// The <paramref name="objectFactory"/> is started in a non-blocking fashion, and the result from it will have to be <c>await</c>ed
/// <param name="lazyFlags">Optional <see cref="AsyncLazyFlags"/> to configure object factory behavior.</param>
42
+
/// <returns>A <see cref="CacheEntityReference{TKey, TValue}"/> representing the lifetime of the underlying <see cref="CacheEntity{TKey, TValue}"/> until disposed.</returns>
/// Determines whether the <see cref="IAsyncMemoryCache{TKey, TValue}"/> contains an element with the specified key.
47
+
/// </summary>
48
+
/// <param name="key">The key to locate in the <see cref="IAsyncMemoryCache{TKey, TValue}"/>.</param>
49
+
/// <returns><see langword="true"/> if the <see cref="IAsyncMemoryCache{TKey, TValue}"/> contains a cache item with the key; otherwise, <see langword="false"/>.</returns>
19
50
boolContainsKey(TKeykey);
51
+
52
+
/// <summary>
53
+
/// Gets the value associated with the specified key.
54
+
/// </summary>
55
+
/// <param name="key">The key whose value to get.</param>
56
+
/// <param name="value">When this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter.</param>
57
+
/// <returns><see langword="true"/> if a cache item with the specified key exists; otherwise <see langword="false"/>.</returns>
Copy file name to clipboardExpand all lines: AsyncMemoryCache/AsyncMemoryCacheConfiguration.cs
+23Lines changed: 23 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -6,20 +6,43 @@
6
6
7
7
namespaceAsyncMemoryCache;
8
8
9
+
/// <summary>
10
+
/// An interface which configures the <see cref="AsyncMemoryCache{TKey, TValue}"/><br/>
11
+
/// Can be used to extend the configuration for use in custom implementations of either <see cref="IAsyncMemoryCache{TKey, TValue}"/> or <see cref="IEvictionBehavior"/>
12
+
/// </summary>
13
+
/// <typeparam name="TKey">The type of the key for cache items represented by the cache.</typeparam>
14
+
/// <typeparam name="TValue">The type of the value which each item in the cache will hold.</typeparam>
/// Sets the <see cref="ExpirationStrategy"/> to a new instance of <see cref="AbsoluteExpirationStrategy"/>.<br/>
33
+
/// This strategy takes an absolute date into account when evaluating whether or not it is expired.<br/>
34
+
/// Useful when more control over the lifetime of a <see cref="CacheEntity{TKey, TValue}"/> is desirable or when there are downsides to having the object alive for an indeterminate amount of time.<br/>
35
+
/// </summary>
36
+
/// <param name="expiryDate">The configurable exact date used when evaluating if the object should be expired.</param>
37
+
/// <returns><see langword="this"/> to enable chained calls</returns>
/// Sets the <see cref="ExpirationStrategy"/> to a new instance of <see cref="SlidingExpirationStrategy"/>.<br/>
46
+
/// This strategy takes the last use of a <see cref="CacheEntity{TKey, TValue}"/> into account when evaluating whether or not it is expired.<br/>
47
+
/// Useful when a cached object is actively used and there is no apparent downside in keeping the cached object alive for an indeterminate amount of time.<br/>
48
+
/// </summary>
49
+
/// <param name="slidingExpirationWindow">The configurable window used when evaluating if the object should be expired.</param>
50
+
/// <returns><see langword="this"/> to enable chained calls</returns>
Copy file name to clipboardExpand all lines: AsyncMemoryCache/CacheEntityReference.cs
+8-1Lines changed: 8 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,16 @@
1
-
usingSystem;
1
+
usingAsyncMemoryCache.EvictionBehaviors;
2
+
usingSystem;
2
3
usingSystem.Diagnostics.CodeAnalysis;
3
4
usingSystem.Threading;
4
5
5
6
namespaceAsyncMemoryCache;
6
7
8
+
/// <summary>
9
+
/// A class representing the lifetime of the underlying cached object.<br/>
10
+
/// As long as this object is referenced/not disposed the cached object will not be evicted or disposed if <see cref="DefaultEvictionBehavior"/> is used.<br/>
11
+
/// </summary>
12
+
/// <typeparam name="TKey">The type of the key for the cache item.</typeparam>
13
+
/// <typeparam name="TValue">The type of the value which the referenced <see cref="CacheEntity{TKey, TValue}"/> wraps.</typeparam>
Copy file name to clipboardExpand all lines: AsyncMemoryCache/EvictionBehaviors/DefaultEvictionBehavior.cs
+6Lines changed: 6 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,12 @@
6
6
7
7
namespaceAsyncMemoryCache.EvictionBehaviors;
8
8
9
+
/// <summary>
10
+
/// The default provided <see cref="IEvictionBehavior"/>.
11
+
/// This class perodically checks for expired items and evicts them. Handling disposal and eviction callbacks as needed.
12
+
/// <para/>
13
+
/// If a cache entity is considered to be expired but still has a live reference via a <see cref="CacheEntityReference{TKey, TValue}"/> object the underlying cached item will not be evicted from the cache.
/// The method which starts the <see cref="IEvictionBehavior"/>.
22
+
/// Called automatically by <see cref="AsyncMemoryCache{TKey, TValue}"/>.
23
+
/// </summary>
24
+
/// <typeparam name="TKey">The type of the key of the <see cref="CacheEntity{TKey, TValue}"/></typeparam>
25
+
/// <typeparam name="TValue">The type of the value of the <see cref="CacheEntity{TKey, TValue}"/></typeparam>
26
+
/// <param name="configuration">The configuration object used in <see cref="AsyncMemoryCache{TKey, TValue}"/> which contains the backing store that holds all of the cached objects</param>
/// Helper method that sets the <see cref="CacheEntity{TKey, TValue}.ExpirationStrategy"/> to a new instance of <see cref="AbsoluteExpirationStrategy"/>.<br/>
10
+
/// This strategy takes an absolute date into account when evaluating whether or not it is expired.<br/>
11
+
/// Useful when more control over the lifetime of a <see cref="CacheEntity{TKey, TValue}"/> is desirable or when there are downsides to having the object alive for an indeterminate amount of time.<para/>
12
+
/// This is a direct proxy to <see cref="CacheEntity{TKey, TValue}.WithAbsoluteExpiration(DateTimeOffset)"/>
@@ -13,6 +22,15 @@ public static CacheEntityReference<TKey, TValue> WithAbsoluteExpiration<TKey, TV
13
22
returncacheEntityReference;
14
23
}
15
24
25
+
/// <summary>
26
+
/// Helper method that sets the <see cref="CacheEntity{TKey, TValue}.ExpirationStrategy"/> to a new instance of <see cref="SlidingExpirationStrategy"/>.<br/>
27
+
/// This strategy takes the last use of a <see cref="CacheEntity{TKey, TValue}"/> into account when evaluating whether or not it is expired.<br/>
28
+
/// Useful when a cached object is actively used and there is no apparent downside in keeping the cached object alive for an indeterminate amount of time.<para/>
29
+
/// This is a direct proxy to <see cref="CacheEntity{TKey, TValue}.WithSlidingExpiration(TimeSpan)"/>
@@ -21,6 +39,13 @@ public static CacheEntityReference<TKey, TValue> WithSlidingExpiration<TKey, TVa
21
39
returncacheEntityReference;
22
40
}
23
41
42
+
/// <summary>
43
+
/// Helper method that sets the <see cref="CacheEntity{TKey, TValue}.ExpirationStrategy"/> to the provided instance of a custom implementation of <see cref="IExpirationStrategy"/>.<br/>
44
+
/// This is a direct proxy to <see cref="CacheEntity{TKey, TValue}.WithExpirationStrategy(IExpirationStrategy)"/>
0 commit comments