Skip to content

Commit 9d2c065

Browse files
committed
Fixing config via json didn't work for bond serializers because of ctor
1 parent 1b8f36f commit 9d2c065

9 files changed

Lines changed: 130 additions & 38 deletions

CacheManager.sln

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "schema", "schema", "{DB13A4
122122
EndProjectSection
123123
EndProject
124124
Global
125+
GlobalSection(Performance) = preSolution
126+
HasPerformanceSessions = true
127+
EndGlobalSection
125128
GlobalSection(SolutionConfigurationPlatforms) = preSolution
126129
Debug|Any CPU = Debug|Any CPU
127130
Release|Any CPU = Release|Any CPU

src/CacheManager.Serialization.Bond/BondCompactBinaryCacheSerializer.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,19 @@ public class BondCompactBinaryCacheSerializer : BondSerializerBase
1818
{
1919
private readonly BinarySerializerCache _cache;
2020

21+
/// <summary>
22+
/// Initializes a new instance of the <see cref="BondCompactBinaryCacheSerializer"/> class.
23+
/// </summary>
24+
public BondCompactBinaryCacheSerializer() : base()
25+
{
26+
_cache = new BinarySerializerCache();
27+
}
28+
2129
/// <summary>
2230
/// Initializes a new instance of the <see cref="BondCompactBinaryCacheSerializer"/> class.
2331
/// </summary>
2432
/// <param name="defaultBufferSize">The default buffer size.</param>
25-
public BondCompactBinaryCacheSerializer(int defaultBufferSize = 1024) : base(defaultBufferSize)
33+
public BondCompactBinaryCacheSerializer(int defaultBufferSize) : base(defaultBufferSize)
2634
{
2735
_cache = new BinarySerializerCache();
2836
}

src/CacheManager.Serialization.Bond/BondFastBinaryCacheSerializer.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,19 @@ public class BondFastBinaryCacheSerializer : BondSerializerBase
1818
{
1919
private readonly FastBinarySerializerCache _cache;
2020

21+
/// <summary>
22+
/// Initializes a new instance of the <see cref="BondFastBinaryCacheSerializer"/> class.
23+
/// </summary>
24+
public BondFastBinaryCacheSerializer() : base()
25+
{
26+
_cache = new FastBinarySerializerCache();
27+
}
28+
2129
/// <summary>
2230
/// Initializes a new instance of the <see cref="BondFastBinaryCacheSerializer"/> class.
2331
/// </summary>
2432
/// <param name="defaultWriteBufferSize">The default buffer size.</param>
25-
public BondFastBinaryCacheSerializer(int defaultWriteBufferSize = 1024) : base(defaultWriteBufferSize)
33+
public BondFastBinaryCacheSerializer(int defaultWriteBufferSize) : base(defaultWriteBufferSize)
2634
{
2735
_cache = new FastBinarySerializerCache();
2836
}

src/CacheManager.Serialization.Bond/BondSerializerBase.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#else
77
using Bond.IO.Safe;
88
#endif
9-
using CacheManager.Core;
109
using CacheManager.Core.Internal;
1110
using CacheManager.Core.Utility;
1211

@@ -22,17 +21,21 @@ public abstract class BondSerializerBase : CacheSerializer
2221
/// <summary>
2322
/// Initializes a new instance of the <see cref="BondSerializerBase"/> class.
2423
/// </summary>
25-
/// <param name="defaultBufferSize">The default buffer size.</param>
26-
public BondSerializerBase(int defaultBufferSize = 1024)
24+
public BondSerializerBase()
25+
: this(1024)
2726
{
28-
OutputBufferPool = new ObjectPool<OutputBuffer>(new OutputBufferPoolPolicy(defaultBufferSize));
29-
StringBuilderPool = new ObjectPool<StringBuilder>(new StringBuilderPoolPolicy(defaultBufferSize));
3027
}
3128

32-
private BondSerializerBase()
29+
/// <summary>
30+
/// Initializes a new instance of the <see cref="BondSerializerBase"/> class.
31+
/// </summary>
32+
/// <param name="defaultBufferSize">The default buffer size.</param>
33+
public BondSerializerBase(int defaultBufferSize)
3334
{
35+
OutputBufferPool = new ObjectPool<OutputBuffer>(new OutputBufferPoolPolicy(defaultBufferSize));
36+
StringBuilderPool = new ObjectPool<StringBuilder>(new StringBuilderPoolPolicy(defaultBufferSize));
3437
}
35-
38+
3639
/// <summary>
3740
/// Gets a pool handling <see cref="OutputBuffer"/>s.
3841
/// </summary>

src/CacheManager.Serialization.Bond/BondSimpleJsonCacheSerializer.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,19 @@ public class BondSimpleJsonCacheSerializer : BondSerializerBase
2020
{
2121
private readonly SimpleJsonSerializerCache _cache;
2222

23+
/// <summary>
24+
/// Initializes a new instance of the <see cref="BondSimpleJsonCacheSerializer"/> class.
25+
/// </summary>
26+
public BondSimpleJsonCacheSerializer() : base()
27+
{
28+
_cache = new SimpleJsonSerializerCache();
29+
}
30+
2331
/// <summary>
2432
/// Initializes a new instance of the <see cref="BondSimpleJsonCacheSerializer"/> class.
2533
/// </summary>
2634
/// <param name="defaultWriteBufferSize">The default buffer size.</param>
27-
public BondSimpleJsonCacheSerializer(int defaultWriteBufferSize = 1024) : base(defaultWriteBufferSize)
35+
public BondSimpleJsonCacheSerializer(int defaultWriteBufferSize) : base(defaultWriteBufferSize)
2836
{
2937
_cache = new SimpleJsonSerializerCache();
3038
}

test/CacheManager.Tests/CacheManagerEventsTest.cs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ public async Task Events_SysRuntime_ExpireTriggers()
228228

229229
string useKey = Guid.NewGuid().ToString();
230230
string useRegion = "@_@23@_!!";
231-
var result = await this.RunTest(cfg, useKey, useRegion);
231+
var result = await RunTest(cfg, useKey, useRegion);
232232

233233
result.Reason.Should().Be(CacheItemRemovedReason.Expired);
234234
result.Level.Should().Be(1);
@@ -248,7 +248,7 @@ public async Task Events_SysRuntime_ExpireEvictsAbove()
248248

249249
string useKey = Guid.NewGuid().ToString();
250250

251-
var result = await this.RunTest(cfg, useKey, null);
251+
var result = await RunTest(cfg, useKey, null);
252252

253253
result.Reason.Should().Be(CacheItemRemovedReason.Expired);
254254
result.Level.Should().Be(2);
@@ -271,7 +271,7 @@ public async Task Events_Dic_ExpireTriggers()
271271

272272
string useKey = Guid.NewGuid().ToString();
273273
string useRegion = "@_@23@_!!";
274-
var result = await this.RunTest(cfg, useKey, useRegion);
274+
var result = await RunTest(cfg, useKey, useRegion);
275275

276276
result.Reason.Should().Be(CacheItemRemovedReason.Expired);
277277
result.Level.Should().Be(1);
@@ -291,7 +291,7 @@ public async Task Events_Dic_ExpireEvictsAbove()
291291

292292
string useKey = Guid.NewGuid().ToString();
293293

294-
var result = await this.RunTest(cfg, useKey, null);
294+
var result = await RunTest(cfg, useKey, null);
295295

296296
result.Reason.Should().Be(CacheItemRemovedReason.Expired);
297297
result.Level.Should().Be(2);
@@ -313,7 +313,7 @@ public async Task Events_MsMemory_ExpireTriggers()
313313

314314
string useKey = Guid.NewGuid().ToString();
315315
string useRegion = "@_@23@_!!";
316-
var result = await this.RunTest(cfg, useKey, useRegion);
316+
var result = await RunTest(cfg, useKey, useRegion);
317317

318318
result.Reason.Should().Be(CacheItemRemovedReason.Expired);
319319
result.Level.Should().Be(1);
@@ -333,7 +333,7 @@ public async Task Events_MsMemory_ExpireEvictsAbove()
333333

334334
string useKey = Guid.NewGuid().ToString();
335335

336-
var result = await this.RunTest(cfg, useKey, null);
336+
var result = await RunTest(cfg, useKey, null);
337337

338338
result.Reason.Should().Be(CacheItemRemovedReason.Expired);
339339
result.Level.Should().Be(2);
@@ -357,7 +357,7 @@ public async Task Events_WebCache_ExpireTriggers()
357357

358358
string useKey = Guid.NewGuid().ToString();
359359
string useRegion = "@_@23@_!!";
360-
var result = await this.RunTest(cfg, useKey, useRegion);
360+
var result = await RunTest(cfg, useKey, useRegion);
361361

362362
result.Reason.Should().Be(CacheItemRemovedReason.Expired);
363363
result.Level.Should().Be(1);
@@ -377,7 +377,7 @@ public async Task Events_WebCache_ExpireEvictsAbove()
377377

378378
string useKey = Guid.NewGuid().ToString();
379379

380-
var result = await this.RunTest(cfg, useKey, null);
380+
var result = await RunTest(cfg, useKey, null);
381381

382382
result.Reason.Should().Be(CacheItemRemovedReason.Expired);
383383
result.Level.Should().Be(2);
@@ -404,7 +404,7 @@ public async Task Events_Redis_ExpireTriggers()
404404

405405
string useKey = Guid.NewGuid().ToString();
406406
string useRegion = "@_@23@_!!";
407-
var result = await this.RunTest(cfg, useKey, useRegion);
407+
var result = await RunTest(cfg, useKey, useRegion);
408408

409409
result.Reason.Should().Be(CacheItemRemovedReason.Expired);
410410
result.Level.Should().Be(1);
@@ -428,7 +428,7 @@ public async Task Events_Redis_ExpireEvictsAbove()
428428

429429
string useKey = Guid.NewGuid().ToString();
430430

431-
var result = await this.RunTest(cfg, useKey, null);
431+
var result = await RunTest(cfg, useKey, null);
432432

433433
result.Reason.Should().Be(CacheItemRemovedReason.Expired);
434434
result.Level.Should().Be(2);
@@ -985,9 +985,9 @@ private class EventCallbackData
985985
{
986986
public EventCallbackData()
987987
{
988-
this.Keys = new List<string>();
989-
this.Regions = new List<string>();
990-
this.Results = new List<UpdateItemResult<object>>();
988+
Keys = new List<string>();
989+
Regions = new List<string>();
990+
Results = new List<UpdateItemResult<object>>();
991991
}
992992

993993
public int Calls { get; set; }
@@ -1003,11 +1003,11 @@ internal void AddCall(CacheActionEventArgs args, params string[] validKeys)
10031003
Guard.NotNullOrEmpty(validKeys, nameof(validKeys));
10041004
if (validKeys.Contains(args.Key))
10051005
{
1006-
this.Calls++;
1007-
this.Keys.Add(args.Key);
1006+
Calls++;
1007+
Keys.Add(args.Key);
10081008
if (!string.IsNullOrWhiteSpace(args.Region))
10091009
{
1010-
this.Regions.Add(args.Region);
1010+
Regions.Add(args.Region);
10111011
}
10121012
}
10131013
}
@@ -1017,11 +1017,11 @@ internal void AddCall(CacheItemRemovedEventArgs args, params string[] validKeys)
10171017
Guard.NotNullOrEmpty(validKeys, nameof(validKeys));
10181018
if (validKeys.Contains(args.Key))
10191019
{
1020-
this.Calls++;
1021-
this.Keys.Add(args.Key);
1020+
Calls++;
1021+
Keys.Add(args.Key);
10221022
if (!string.IsNullOrWhiteSpace(args.Region))
10231023
{
1024-
this.Regions.Add(args.Region);
1024+
Regions.Add(args.Region);
10251025
}
10261026
}
10271027
}
@@ -1031,14 +1031,14 @@ internal void AddCall(CacheClearRegionEventArgs args, params string[] validKeys)
10311031
Guard.NotNullOrEmpty(validKeys, nameof(validKeys));
10321032
if (validKeys.Contains(args.Region))
10331033
{
1034-
this.Calls++;
1035-
this.Regions.Add(args.Region);
1034+
Calls++;
1035+
Regions.Add(args.Region);
10361036
}
10371037
}
10381038

10391039
internal void AddCall()
10401040
{
1041-
this.Calls++;
1041+
Calls++;
10421042
}
10431043
}
10441044

@@ -1051,7 +1051,7 @@ public CustomRemoveEventTestHandle(ICacheManagerConfiguration managerConfigurati
10511051

10521052
public void TestTrigger(string key, string region, CacheItemRemovedReason reason)
10531053
{
1054-
this.TriggerCacheSpecificRemove(key, region, reason);
1054+
TriggerCacheSpecificRemove(key, region, reason);
10551055
}
10561056

10571057
public override int Count

0 commit comments

Comments
 (0)