Skip to content

Commit cea5b80

Browse files
committed
Enable Nullable in all projects
1 parent 91e8457 commit cea5b80

10 files changed

Lines changed: 73 additions & 58 deletions

File tree

Neolution.Extensions.Caching.Abstractions/DistributedCache.cs

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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))

Neolution.Extensions.Caching.Abstractions/IDistributedCache.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public interface IDistributedCache<in TCacheId>
2323
/// <typeparam name="T">The type of the cache identifier.</typeparam>
2424
/// <param name="id">An enum value identifying the requested value.</param>
2525
/// <returns>The located value or null.</returns>
26-
T Get<T>(TCacheId id)
26+
T? Get<T>(TCacheId id)
2727
where T : class;
2828

2929
/// <summary>
@@ -33,7 +33,7 @@ T Get<T>(TCacheId id)
3333
/// <param name="id">An enum value identifying the requested value.</param>
3434
/// <param name="key">The key.</param>
3535
/// <returns>The located value or null.</returns>
36-
T Get<T>(TCacheId id, string key)
36+
T? Get<T>(TCacheId id, string key)
3737
where T : class;
3838

3939
/// <summary>
@@ -45,7 +45,7 @@ T Get<T>(TCacheId id, string key)
4545
/// <returns>
4646
/// The <see cref="Task" /> that represents the asynchronous operation, containing the located value or null.
4747
/// </returns>
48-
Task<T> GetAsync<T>(TCacheId id, CancellationToken token = default)
48+
Task<T?> GetAsync<T>(TCacheId id, CancellationToken token = default)
4949
where T : class;
5050

5151
/// <summary>
@@ -58,7 +58,7 @@ Task<T> GetAsync<T>(TCacheId id, CancellationToken token = default)
5858
/// <returns>
5959
/// The <see cref="Task" /> that represents the asynchronous operation, containing the located value or null.
6060
/// </returns>
61-
Task<T> GetAsync<T>(TCacheId id, string key, CancellationToken token = default)
61+
Task<T?> GetAsync<T>(TCacheId id, string key, CancellationToken token = default)
6262
where T : class;
6363

6464
/// <summary>
@@ -114,7 +114,7 @@ Task SetAsync<T>(TCacheId id, string key, T value, CancellationToken token = def
114114
/// <param name="id">An enum value identifying the requested value.</param>
115115
/// <param name="value">The value to set in the cache.</param>
116116
/// <param name="options">The cache options for the value.</param>
117-
void SetWithOptions<T>(TCacheId id, T value, CacheEntryOptions options)
117+
void SetWithOptions<T>(TCacheId id, T value, CacheEntryOptions? options)
118118
where T : class;
119119

120120
/// <summary>
@@ -125,7 +125,7 @@ void SetWithOptions<T>(TCacheId id, T value, CacheEntryOptions options)
125125
/// <param name="key">The key.</param>
126126
/// <param name="value">The value to set in the cache.</param>
127127
/// <param name="options">The cache options for the value.</param>
128-
void SetWithOptions<T>(TCacheId id, string key, T value, CacheEntryOptions options)
128+
void SetWithOptions<T>(TCacheId id, string key, T value, CacheEntryOptions? options)
129129
where T : class;
130130

131131
/// <summary>
@@ -139,7 +139,7 @@ void SetWithOptions<T>(TCacheId id, string key, T value, CacheEntryOptions optio
139139
/// <returns>
140140
/// The <see cref="Task" /> that represents the asynchronous operation.
141141
/// </returns>
142-
Task SetWithOptionsAsync<T>(TCacheId id, T value, CacheEntryOptions options, CancellationToken token = default)
142+
Task SetWithOptionsAsync<T>(TCacheId id, T value, CacheEntryOptions? options, CancellationToken token = default)
143143
where T : class;
144144

145145
/// <summary>
@@ -154,7 +154,7 @@ Task SetWithOptionsAsync<T>(TCacheId id, T value, CacheEntryOptions options, Can
154154
/// <returns>
155155
/// The <see cref="Task" /> that represents the asynchronous operation.
156156
/// </returns>
157-
Task SetWithOptionsAsync<T>(TCacheId id, string key, T value, CacheEntryOptions options, CancellationToken token = default)
157+
Task SetWithOptionsAsync<T>(TCacheId id, string key, T value, CacheEntryOptions? options, CancellationToken token = default)
158158
where T : class;
159159

160160
/// <summary>

Neolution.Extensions.Caching.Abstractions/IMemoryCache.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public interface IMemoryCache<in TCacheId>
5555
/// <param name="id">The cache identifier.</param>
5656
/// <param name="value">The value to cache.</param>
5757
/// <param name="options">The options.</param>
58-
void SetWithOptions<T>(TCacheId id, T value, CacheEntryOptions options);
58+
void SetWithOptions<T>(TCacheId id, T value, CacheEntryOptions? options);
5959

6060
/// <summary>
6161
/// Create or overwrite an entry in the cache with options.
@@ -65,7 +65,7 @@ public interface IMemoryCache<in TCacheId>
6565
/// <param name="key">An object identifying the entry.</param>
6666
/// <param name="value">The value to cache.</param>
6767
/// <param name="options">The options.</param>
68-
void SetWithOptions<T>(TCacheId id, string key, T value, CacheEntryOptions options);
68+
void SetWithOptions<T>(TCacheId id, string key, T value, CacheEntryOptions? options);
6969

7070
/// <summary>
7171
/// Removes the object associated with the given id.

Neolution.Extensions.Caching.Abstractions/MemoryCache.cs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,60 +12,62 @@ public abstract class MemoryCache<TCacheId> : IMemoryCache<TCacheId>
1212
/// <summary>
1313
/// Gets the name of the cache.
1414
/// </summary>
15-
/// <value>
16-
/// The name of the cache.
17-
/// </value>
1815
private static string CacheIdName => typeof(TCacheId).Name;
1916

2017
/// <inheritdoc />
2118
public T Get<T>(TCacheId id)
2219
{
23-
return this.Get<T>(id, null);
20+
var cacheKey = CreateCacheKey(id);
21+
return this.GetCacheObject<T>(cacheKey);
2422
}
2523

2624
/// <inheritdoc />
2725
public T Get<T>(TCacheId id, string key)
2826
{
29-
key = CreateCacheKey(id, key);
30-
return this.GetCacheObject<T>(key);
27+
var cacheKey = CreateCacheKey(id, key);
28+
return this.GetCacheObject<T>(cacheKey);
3129
}
3230

3331
/// <inheritdoc />
3432
public void Set<T>(TCacheId id, T value)
3533
{
36-
this.SetWithOptions(id, null, value, null);
34+
var cacheKey = CreateCacheKey(id);
35+
this.SetCacheObject(cacheKey, value, new CacheEntryOptions());
3736
}
3837

3938
/// <inheritdoc />
4039
public void Set<T>(TCacheId id, string key, T value)
4140
{
42-
this.SetWithOptions(id, key, value, null);
41+
var cacheKey = CreateCacheKey(id, key);
42+
this.SetCacheObject(cacheKey, value, new CacheEntryOptions());
4343
}
4444

4545
/// <inheritdoc />
46-
public void SetWithOptions<T>(TCacheId id, T value, CacheEntryOptions options)
46+
public void SetWithOptions<T>(TCacheId id, T value, CacheEntryOptions? options)
4747
{
48-
this.SetWithOptions(id, null, value, options);
48+
var cacheKey = CreateCacheKey(id);
49+
this.SetCacheObject(cacheKey, value, options);
4950
}
5051

5152
/// <inheritdoc />
52-
public void SetWithOptions<T>(TCacheId id, string key, T value, CacheEntryOptions options)
53+
public void SetWithOptions<T>(TCacheId id, string key, T value, CacheEntryOptions? options)
5354
{
54-
key = CreateCacheKey(id, key);
55-
this.SetCacheObject(key, value, options);
55+
var cacheKey = CreateCacheKey(id, key);
56+
this.SetCacheObject(cacheKey, value, options);
5657
}
5758

5859
/// <inheritdoc />
5960
public void Remove(TCacheId id)
6061
{
61-
this.Remove(id, null);
62+
var cacheKey = CreateCacheKey(id);
63+
this.RemoveCacheObject(cacheKey);
6264
}
6365

6466
/// <inheritdoc />
6567
public void Remove(TCacheId id, string key)
6668
{
67-
key = CreateCacheKey(id, key);
68-
this.RemoveCacheObject(key);
69+
var cacheKey = CreateCacheKey(id, key);
70+
this.RemoveCacheObject(cacheKey);
6971
}
7072

7173
/// <summary>
@@ -83,7 +85,7 @@ public void Remove(TCacheId id, string key)
8385
/// <param name="key">The key.</param>
8486
/// <param name="value">The value.</param>
8587
/// <param name="options">The options.</param>
86-
protected abstract void SetCacheObject<T>(string key, T value, CacheEntryOptions options);
88+
protected abstract void SetCacheObject<T>(string key, T value, CacheEntryOptions? options);
8789

8890
/// <summary>
8991
/// Resets the object in the cache.
@@ -97,7 +99,7 @@ public void Remove(TCacheId id, string key)
9799
/// <param name="container">The container.</param>
98100
/// <param name="key">The key.</param>
99101
/// <returns>The cache key</returns>
100-
private static string CreateCacheKey(TCacheId container, string key = null)
102+
private static string CreateCacheKey(TCacheId container, string? key = null)
101103
{
102104
var containerName = container.ToString();
103105
if (!string.IsNullOrWhiteSpace(key))

Neolution.Extensions.Caching.Abstractions/Neolution.Extensions.Caching.Abstractions.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
55
<LangVersion>latest</LangVersion>
6+
<Nullable>enable</Nullable>
67
</PropertyGroup>
78

89
<ItemGroup>

Neolution.Extensions.Caching.Distributed/MessagePackDistributedCache.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ public MessagePackDistributedCache(IDistributedCache cache, IOptions<MessagePack
7070
}
7171

7272
/// <inheritdoc />
73-
protected override void SetCacheObject<T>(string key, T value, CacheEntryOptions options)
73+
protected override void SetCacheObject<T>(string key, T value, CacheEntryOptions? options)
7474
{
7575
var bytes = MessagePackSerializer.Serialize(value, this.serializerOptions);
7676
this.cache.Set(key, bytes, ConvertOptions(options));
7777
}
7878

7979
/// <inheritdoc />
80-
protected override async Task SetCacheObjectAsync<T>(string key, T value, CacheEntryOptions options, CancellationToken token)
80+
protected override async Task SetCacheObjectAsync<T>(string key, T value, CacheEntryOptions? options, CancellationToken token)
8181
{
8282
var bytes = MessagePackSerializer.Serialize(value, this.serializerOptions, token);
8383
await this.cache.SetAsync(key, bytes, ConvertOptions(options), token).ConfigureAwait(false);
@@ -100,7 +100,7 @@ protected override async Task RemoveCacheObjectAsync(string key, CancellationTok
100100
/// </summary>
101101
/// <param name="options">The options.</param>
102102
/// <returns>The <see cref="DistributedCacheEntryOptions"/>.</returns>
103-
private static DistributedCacheEntryOptions ConvertOptions(CacheEntryOptions options)
103+
private static DistributedCacheEntryOptions ConvertOptions(CacheEntryOptions? options)
104104
{
105105
if (options == null)
106106
{

Neolution.Extensions.Caching.InMemory/InMemoryCache.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ protected override T GetCacheObject<T>(string key)
3232
}
3333

3434
/// <inheritdoc />
35-
protected override void SetCacheObject<T>(string key, T value, CacheEntryOptions options)
35+
protected override void SetCacheObject<T>(string key, T value, CacheEntryOptions? options)
3636
{
3737
var opt = new MemoryCacheEntryOptions();
3838
if (options != null)

0 commit comments

Comments
 (0)