Skip to content

Commit 9370086

Browse files
committed
Use contract-less resolver by default
1 parent 3fad2b1 commit 9370086

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

Neolution.Extensions.Caching.Distributed/MessagePackDistributedCache.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ public class MessagePackDistributedCache<TCacheId> : DistributedCache<TCacheId>
2222
private readonly IDistributedCache cache;
2323

2424
/// <summary>
25-
/// The serializer options. Uses compression by default.
25+
/// The serializer options. Uses contract-less serialization and compression by default.
2626
/// </summary>
27-
private readonly MessagePackSerializerOptions serializerOptions = MessagePackSerializerOptions.Standard.WithCompression(MessagePackCompression.Lz4BlockArray);
27+
private readonly MessagePackSerializerOptions serializerOptions = MessagePack.Resolvers.ContractlessStandardResolver.Options
28+
.WithCompression(MessagePackCompression.Lz4BlockArray);
2829

2930
/// <summary>
3031
/// Initializes a new instance of the <see cref="MessagePackDistributedCache{TCacheId}"/> class.
@@ -41,6 +42,11 @@ public MessagePackDistributedCache(IDistributedCache cache, IOptions<MessagePack
4142
}
4243

4344
var options = optionsAccessor.Value;
45+
if (options.RequireMessagePackObjectAnnotation)
46+
{
47+
this.serializerOptions = MessagePackSerializerOptions.Standard;
48+
}
49+
4450
if (options.DisableCompression)
4551
{
4652
this.serializerOptions = this.serializerOptions.WithCompression(MessagePackCompression.None);

Neolution.Extensions.Caching.Distributed/MessagePackDistributedCacheOptions.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ public class MessagePackDistributedCacheOptions : IOptions<MessagePackDistribute
1212
/// </summary>
1313
public bool DisableCompression { get; set; }
1414

15+
/// <summary>
16+
/// Gets or sets a value indicating whether to require <see cref="MessagePack.MessagePackObjectAttribute"/> annotation for serializable types.
17+
/// Doing so would result in better overall serialization performance and smaller files.
18+
/// </summary>
19+
/// <value>
20+
/// <c>true</c> to require <see cref="MessagePack.MessagePackObjectAttribute"/> annotation; otherwise, <c>false</c>.
21+
/// </value>
22+
public bool RequireMessagePackObjectAnnotation { get; set; }
23+
1524
/// <inheritdoc />
1625
public MessagePackDistributedCacheOptions Value => this;
1726
}

0 commit comments

Comments
 (0)