-
-
Notifications
You must be signed in to change notification settings - Fork 36
/
ICacheLayer.cs
64 lines (61 loc) · 2.57 KB
/
ICacheLayer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System.Threading.Tasks;
namespace CacheTower
{
/// <summary>
/// Cache layers represent individual types of caching solutions including in-memory, file-based and Redis.
/// It is with cache layers that items are set, retrieved or evicted from the cache.
/// </summary>
public interface ICacheLayer
{
/// <summary>
/// Flushes the cache layer, removing every item from the cache.
/// </summary>
/// <returns></returns>
ValueTask FlushAsync();
/// <summary>
/// Triggers the cleanup of any cache entries that are expired.
/// </summary>
/// <returns></returns>
ValueTask CleanupAsync();
/// <summary>
/// Removes an entry with the corresponding <paramref name="cacheKey"/> from the cache layer.
/// </summary>
/// <param name="cacheKey">The cache entry's key.</param>
/// <returns></returns>
ValueTask EvictAsync(string cacheKey);
/// <summary>
/// Retrieves the <see cref="CacheEntry{T}"/> for a given <paramref name="cacheKey"/>.
/// </summary>
/// <typeparam name="T">The type of value in the cache entry.</typeparam>
/// <param name="cacheKey">The cache entry's key.</param>
/// <returns>The existing cache entry or <c>null</c> if no entry is found.</returns>
ValueTask<CacheEntry<T>?> GetAsync<T>(string cacheKey);
/// <summary>
/// Caches <paramref name="cacheEntry"/> against the <paramref name="cacheKey"/>.
/// </summary>
/// <typeparam name="T">The type of value in the cache entry.</typeparam>
/// <param name="cacheKey">The cache entry's key.</param>
/// <param name="cacheEntry">The cache entry to store.</param>
/// <returns></returns>
ValueTask SetAsync<T>(string cacheKey, CacheEntry<T> cacheEntry);
/// <summary>
/// Retrieves the current availability status of the cache layer.
/// This is used by <see cref="CacheStack"/> to determine whether a value can even be cached at that moment in time.
/// </summary>
/// <param name="cacheKey"></param>
/// <returns></returns>
ValueTask<bool> IsAvailableAsync(string cacheKey);
}
/// <inheritdoc/>
/// <remarks>
/// A local cache layer represents a cache not shared with multiple instances of your application.
/// For example, an in-memory cache layer would be an example of a local cache layer.
/// </remarks>
public interface ILocalCacheLayer : ICacheLayer { }
/// <inheritdoc/>
/// <remarks>
/// A distributed cache layer represents a cache that is shared with multiple instances of your application.
/// For example, a Redis cache layer would be an example of a distributed cache layer.
/// </remarks>
public interface IDistributedCacheLayer : ICacheLayer { }
}