Skip to content

Commit 5ce886c

Browse files
Added a hashed key property to the cache query result interfaces
1 parent 5e7a546 commit 5ce886c

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

src/DotNetToolkit.Repository/Extensions/CachingProviderExtensions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static ICacheQueryResult<TResult> GetOrSet<TEntity, TResult>(
6363
cacheUsed = true;
6464
}
6565

66-
return new CacheQueryResult<TResult>(value)
66+
return new CacheQueryResult<TResult>(hashedKey, value)
6767
{
6868
CacheUsed = cacheUsed
6969
};
@@ -106,7 +106,7 @@ public static ICachePagedQueryResult<TResult> GetOrSet<TEntity, TResult>(
106106
cacheUsed = true;
107107
}
108108

109-
return new CachePagedQueryResult<TResult>(value)
109+
return new CachePagedQueryResult<TResult>(hashedKey, value)
110110
{
111111
CacheUsed = cacheUsed
112112
};
@@ -149,7 +149,7 @@ public static async Task<ICacheQueryResult<TResult>> GetOrSetAsync<TEntity, TRes
149149
cacheUsed = true;
150150
}
151151

152-
return new CacheQueryResult<TResult>(value)
152+
return new CacheQueryResult<TResult>(hashedKey, value)
153153
{
154154
CacheUsed = cacheUsed
155155
};
@@ -192,7 +192,7 @@ public static async Task<ICachePagedQueryResult<TResult>> GetOrSetAsync<TEntity,
192192
cacheUsed = true;
193193
}
194194

195-
return new CachePagedQueryResult<TResult>(value)
195+
return new CachePagedQueryResult<TResult>(hashedKey, value)
196196
{
197197
CacheUsed = cacheUsed
198198
};

src/DotNetToolkit.Repository/Queries/ICacheQueryResult.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
/// <typeparam name="TResult">The type of the result.</typeparam>
77
public interface ICacheQueryResult<out TResult>
88
{
9+
/// <summary>
10+
/// Gets the hashed key associated to this cached result.
11+
/// </summary>
12+
string HashedKey { get; }
13+
914
/// <summary>
1015
/// Gets the result.
1116
/// </summary>

src/DotNetToolkit.Repository/Queries/Internal/CachePagedQueryResult.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ internal class CachePagedQueryResult<TResult> : CacheQueryResult<IPagedQueryResu
1111
/// <summary>
1212
/// Initializes a new instance of the <see cref="CachePagedQueryResult{TResult}"/> class.
1313
/// </summary>
14+
/// <param name="hashedKey">The hashed key.</param>
1415
/// <param name="result">The result.</param>
15-
public CachePagedQueryResult([CanBeNull] IPagedQueryResult<TResult> result) : base(result) { }
16+
public CachePagedQueryResult([NotNull] string hashedKey, [CanBeNull] IPagedQueryResult<TResult> result) : base(hashedKey, result) { }
1617
}
1718
}

src/DotNetToolkit.Repository/Queries/Internal/CacheQueryResult.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
namespace DotNetToolkit.Repository.Queries.Internal
22
{
33
using JetBrains.Annotations;
4+
using Utility;
45

56
/// <summary>
67
/// An implementation of <see cref="ICacheQueryResult{TResult}" />.
78
/// </summary>
89
/// <typeparam name="TResult">The type of the result.</typeparam>
910
internal class CacheQueryResult<TResult> : ICacheQueryResult<TResult>
1011
{
12+
/// <summary>
13+
/// Gets the hashed key associated to this cached result.
14+
/// </summary>
15+
public string HashedKey { get; }
16+
1117
/// <summary>
1218
/// Gets the result.
1319
/// </summary>
@@ -21,9 +27,11 @@ internal class CacheQueryResult<TResult> : ICacheQueryResult<TResult>
2127
/// <summary>
2228
/// Initializes a new instance of the <see cref="CacheQueryResult{TResult}"/> class.
2329
/// </summary>
30+
/// <param name="hashedKey">The hashed key.</param>
2431
/// <param name="result">The result.</param>
25-
public CacheQueryResult([CanBeNull] TResult result)
32+
public CacheQueryResult([NotNull] string hashedKey, [CanBeNull] TResult result)
2633
{
34+
HashedKey = Guard.NotEmpty(hashedKey, nameof(hashedKey));
2735
Result = result;
2836
}
2937
}

0 commit comments

Comments
 (0)