@@ -20,29 +20,31 @@ public abstract class DistributedCache<TCacheId> : IDistributedCache<TCacheId>
2020 private static string CacheIdName => typeof ( TCacheId ) . Name ;
2121
2222 /// <inheritdoc />
23- public T Get < T > ( TCacheId id )
23+ public T ? Get < T > ( TCacheId id )
2424 where T : class
2525 {
26- return this . Get < T > ( id , null ) ;
26+ var cacheKey = CreateCacheKey ( id ) ;
27+ return this . GetCacheObject < T > ( cacheKey ) ;
2728 }
2829
2930 /// <inheritdoc />
30- public T Get < T > ( TCacheId id , string key )
31+ public T ? Get < T > ( TCacheId id , string key )
3132 where T : class
3233 {
3334 var cacheKey = CreateCacheKey ( id , key ) ;
3435 return this . GetCacheObject < T > ( cacheKey ) ;
3536 }
3637
3738 /// <inheritdoc />
38- public Task < T > GetAsync < T > ( TCacheId id , CancellationToken token = default )
39+ public Task < T ? > GetAsync < T > ( TCacheId id , CancellationToken token = default )
3940 where T : class
4041 {
41- return this . GetAsync < T > ( id , null , token ) ;
42+ var cacheKey = CreateCacheKey ( id ) ;
43+ return this . GetCacheObjectAsync < T > ( cacheKey , token ) ;
4244 }
4345
4446 /// <inheritdoc />
45- public Task < T > GetAsync < T > ( TCacheId id , string key , CancellationToken token = default )
47+ public Task < T ? > GetAsync < T > ( TCacheId id , string key , CancellationToken token = default )
4648 where T : class
4749 {
4850 var cacheKey = CreateCacheKey ( id , key ) ;
@@ -53,22 +55,24 @@ public Task<T> GetAsync<T>(TCacheId id, string key, CancellationToken token = de
5355 public void Set < T > ( TCacheId id , T value )
5456 where T : class
5557 {
56- this . Set ( id , null , value ) ;
58+ var cacheKey = CreateCacheKey ( id ) ;
59+ this . SetCacheObject ( cacheKey , value , new CacheEntryOptions ( ) ) ;
5760 }
5861
5962 /// <inheritdoc />
6063 public void Set < T > ( TCacheId id , string key , T value )
6164 where T : class
6265 {
6366 var cacheKey = CreateCacheKey ( id , key ) ;
64- this . SetCacheObject ( cacheKey , value , null ) ;
67+ this . SetCacheObject ( cacheKey , value , new CacheEntryOptions ( ) ) ;
6568 }
6669
6770 /// <inheritdoc />
6871 public Task SetAsync < T > ( TCacheId id , T value , CancellationToken token = default )
6972 where T : class
7073 {
71- return this . SetAsync ( id , null , value , token ) ;
74+ var cacheKey = CreateCacheKey ( id ) ;
75+ return this . SetCacheObjectAsync ( cacheKey , value , new CacheEntryOptions ( ) , token ) ;
7276 }
7377
7478 /// <inheritdoc />
@@ -80,29 +84,31 @@ public Task SetAsync<T>(TCacheId id, string key, T value, CancellationToken toke
8084 }
8185
8286 /// <inheritdoc />
83- public void SetWithOptions < T > ( TCacheId id , T value , CacheEntryOptions options )
87+ public void SetWithOptions < T > ( TCacheId id , T value , CacheEntryOptions ? options )
8488 where T : class
8589 {
86- this . SetWithOptions ( id , null , value , options ) ;
90+ var cacheKey = CreateCacheKey ( id ) ;
91+ this . SetCacheObject ( cacheKey , value , options ) ;
8792 }
8893
8994 /// <inheritdoc />
90- public void SetWithOptions < T > ( TCacheId id , string key , T value , CacheEntryOptions options )
95+ public void SetWithOptions < T > ( TCacheId id , string key , T value , CacheEntryOptions ? options )
9196 where T : class
9297 {
9398 var cacheKey = CreateCacheKey ( id , key ) ;
9499 this . SetCacheObject ( cacheKey , value , options ) ;
95100 }
96101
97102 /// <inheritdoc />
98- public Task SetWithOptionsAsync < T > ( TCacheId id , T value , CacheEntryOptions options , CancellationToken token = default )
103+ public Task SetWithOptionsAsync < T > ( TCacheId id , T value , CacheEntryOptions ? options , CancellationToken token = default )
99104 where T : class
100105 {
101- return this . SetWithOptionsAsync ( id , null , value , options , token ) ;
106+ var cacheKey = CreateCacheKey ( id ) ;
107+ return this . SetCacheObjectAsync ( cacheKey , value , options , token ) ;
102108 }
103109
104110 /// <inheritdoc />
105- public Task SetWithOptionsAsync < T > ( TCacheId id , string key , T value , CacheEntryOptions options , CancellationToken token = default )
111+ public Task SetWithOptionsAsync < T > ( TCacheId id , string key , T value , CacheEntryOptions ? options , CancellationToken token = default )
106112 where T : class
107113 {
108114 var cacheKey = CreateCacheKey ( id , key ) ;
@@ -112,7 +118,8 @@ public Task SetWithOptionsAsync<T>(TCacheId id, string key, T value, CacheEntryO
112118 /// <inheritdoc />
113119 public void Remove ( TCacheId id )
114120 {
115- this . Remove ( id , null ) ;
121+ var cacheKey = CreateCacheKey ( id ) ;
122+ this . RemoveCacheObject ( cacheKey ) ;
116123 }
117124
118125 /// <inheritdoc />
@@ -125,7 +132,8 @@ public void Remove(TCacheId id, string key)
125132 /// <inheritdoc />
126133 public Task RemoveAsync ( TCacheId id , CancellationToken token = default )
127134 {
128- return this . RemoveAsync ( id , null , token ) ;
135+ var cacheKey = CreateCacheKey ( id ) ;
136+ return this . RemoveCacheObjectAsync ( cacheKey , token ) ;
129137 }
130138
131139 /// <inheritdoc />
@@ -143,7 +151,7 @@ public Task RemoveAsync(TCacheId id, string key, CancellationToken token = defau
143151 /// <returns>
144152 /// The object from the cache
145153 /// </returns>
146- protected abstract T GetCacheObject < T > ( string key )
154+ protected abstract T ? GetCacheObject < T > ( string key )
147155 where T : class ;
148156
149157 /// <summary>
@@ -153,7 +161,7 @@ protected abstract T GetCacheObject<T>(string key)
153161 /// <param name="key">The key.</param>
154162 /// <param name="token">Optional. The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
155163 /// <returns>The object from the cache</returns>
156- protected abstract Task < T > GetCacheObjectAsync < T > ( string key , CancellationToken token )
164+ protected abstract Task < T ? > GetCacheObjectAsync < T > ( string key , CancellationToken token )
157165 where T : class ;
158166
159167 /// <summary>
@@ -163,7 +171,7 @@ protected abstract Task<T> GetCacheObjectAsync<T>(string key, CancellationToken
163171 /// <param name="key">The key.</param>
164172 /// <param name="value">The value.</param>
165173 /// <param name="options">The options.</param>
166- protected abstract void SetCacheObject < T > ( string key , T value , CacheEntryOptions options )
174+ protected abstract void SetCacheObject < T > ( string key , T value , CacheEntryOptions ? options )
167175 where T : class ;
168176
169177 /// <summary>
@@ -175,7 +183,7 @@ protected abstract void SetCacheObject<T>(string key, T value, CacheEntryOptions
175183 /// <param name="options">The options.</param>
176184 /// <param name="token">Optional. The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
177185 /// <returns>The <see cref="Task"/>.</returns>
178- protected abstract Task SetCacheObjectAsync < T > ( string key , T value , CacheEntryOptions options , CancellationToken token )
186+ protected abstract Task SetCacheObjectAsync < T > ( string key , T value , CacheEntryOptions ? options , CancellationToken token )
179187 where T : class ;
180188
181189 /// <summary>
@@ -198,7 +206,7 @@ protected abstract Task SetCacheObjectAsync<T>(string key, T value, CacheEntryOp
198206 /// <param name="id">The cache id.</param>
199207 /// <param name="key">The key of the cache entry.</param>
200208 /// <returns>The caching key.</returns>
201- private static string CreateCacheKey ( TCacheId id , string key = null )
209+ private static string CreateCacheKey ( TCacheId id , string ? key = null )
202210 {
203211 var cacheKey = id . ToString ( ) ;
204212 if ( ! string . IsNullOrWhiteSpace ( key ) )
0 commit comments