Skip to content

Commit 459e840

Browse files
Replace ICache interface by a CacheBase class
1 parent 9f2997c commit 459e840

File tree

63 files changed

+1508
-1025
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1508
-1025
lines changed

src/AsyncGenerator.yml

-2
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,6 @@ methodRules:
267267
name: Lock
268268
- containingType: NHibernate.Cache.ICache
269269
name: Unlock
270-
- containingType: NHibernate.Cache.IBatchableReadOnlyCache
271-
- containingType: NHibernate.Cache.IBatchableCache
272270
name: Cache
273271
- filters:
274272
- containingNamespace: NHibernate

src/NHibernate.Test/Async/CacheTest/CacheFixture.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ private CacheKey CreateCacheKey(string text)
3434

3535
public async Task DoTestCacheAsync(ICacheProvider cacheProvider, CancellationToken cancellationToken = default(CancellationToken))
3636
{
37-
ICache cache = cacheProvider.BuildCache(typeof(String).FullName, new Dictionary<string, string>());
37+
var cache = cacheProvider.BuildCache(typeof(String).FullName, new Dictionary<string, string>());
3838

3939
long longBefore = Timestamper.Next();
4040

@@ -141,7 +141,7 @@ private CacheKey CreateCacheKey(string text)
141141
Assert.AreEqual("baz", await (ccs.GetAsync(fooKey, longLongAfter, cancellationToken)));
142142
}
143143

144-
private async Task DoTestMinValueTimestampOnStrategyAsync(ICache cache, ICacheConcurrencyStrategy strategy, CancellationToken cancellationToken = default(CancellationToken))
144+
private async Task DoTestMinValueTimestampOnStrategyAsync(CacheBase cache, ICacheConcurrencyStrategy strategy, CancellationToken cancellationToken = default(CancellationToken))
145145
{
146146
CacheKey key = CreateCacheKey("key");
147147
strategy.Cache = cache;
@@ -154,7 +154,7 @@ private CacheKey CreateCacheKey(string text)
154154
[Test]
155155
public async Task MinValueTimestampAsync()
156156
{
157-
ICache cache = new HashtableCacheProvider().BuildCache("region", new Dictionary<string, string>());
157+
var cache = new HashtableCacheProvider().BuildCache("region", new Dictionary<string, string>());
158158
ICacheConcurrencyStrategy strategy = new ReadWriteCache();
159159
strategy.Cache = cache;
160160

@@ -163,4 +163,4 @@ public async Task MinValueTimestampAsync()
163163
await (DoTestMinValueTimestampOnStrategyAsync(cache, new ReadOnlyCache()));
164164
}
165165
}
166-
}
166+
}

src/NHibernate.Test/Async/CacheTest/Caches/BatchableCache.cs

+40-54
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,36 @@
88
//------------------------------------------------------------------------------
99

1010

11-
using System;
1211
using System.Collections;
1312
using System.Collections.Generic;
14-
using System.Linq;
15-
using System.Text;
16-
using System.Threading;
17-
using System.Threading.Tasks;
1813
using NHibernate.Cache;
1914

2015
namespace NHibernate.Test.CacheTest.Caches
2116
{
22-
public partial class BatchableCache : ICache, IBatchableCache
17+
using System.Threading.Tasks;
18+
using System.Threading;
19+
public partial class BatchableCache : CacheBase
2320
{
2421

25-
public Task PutManyAsync(object[] keys, object[] values, CancellationToken cancellationToken)
22+
public override Task<object[]> GetManyAsync(object[] keys, CancellationToken cancellationToken)
23+
{
24+
try
25+
{
26+
GetMultipleCalls.Add(keys);
27+
var result = new object[keys.Length];
28+
for (var i = 0; i < keys.Length; i++)
29+
{
30+
result[i] = _hashtable[keys[i]];
31+
}
32+
return Task.FromResult<object[]>(result);
33+
}
34+
catch (System.Exception ex)
35+
{
36+
return Task.FromException<object[]>(ex);
37+
}
38+
}
39+
40+
public override Task PutManyAsync(object[] keys, object[] values, CancellationToken cancellationToken)
2641
{
2742
try
2843
{
@@ -33,130 +48,101 @@ public Task PutManyAsync(object[] keys, object[] values, CancellationToken cance
3348
}
3449
return Task.CompletedTask;
3550
}
36-
catch (Exception ex)
51+
catch (System.Exception ex)
3752
{
3853
return Task.FromException<object>(ex);
3954
}
4055
}
4156

42-
public Task<object> LockManyAsync(object[] keys, CancellationToken cancellationToken)
57+
public override Task<object> LockManyAsync(object[] keys, CancellationToken cancellationToken)
4358
{
4459
try
4560
{
4661
LockMultipleCalls.Add(keys);
4762
return Task.FromResult<object>(null);
4863
}
49-
catch (Exception ex)
64+
catch (System.Exception ex)
5065
{
5166
return Task.FromException<object>(ex);
5267
}
5368
}
5469

55-
public Task UnlockManyAsync(object[] keys, object lockValue, CancellationToken cancellationToken)
70+
public override Task UnlockManyAsync(object[] keys, object lockValue, CancellationToken cancellationToken)
5671
{
5772
try
5873
{
5974
UnlockMultipleCalls.Add(keys);
6075
return Task.CompletedTask;
6176
}
62-
catch (Exception ex)
77+
catch (System.Exception ex)
6378
{
6479
return Task.FromException<object>(ex);
6580
}
6681
}
6782

68-
#region ICache Members
69-
70-
/// <summary></summary>
71-
public Task<object> GetAsync(object key, CancellationToken cancellationToken)
83+
public override Task<object> GetAsync(object key, CancellationToken cancellationToken)
7284
{
7385
try
7486
{
7587
GetCalls.Add(key);
7688
return Task.FromResult<object>(_hashtable[key]);
7789
}
78-
catch (Exception ex)
90+
catch (System.Exception ex)
7991
{
8092
return Task.FromException<object>(ex);
8193
}
8294
}
8395

84-
public Task<object[]> GetManyAsync(object[] keys, CancellationToken cancellationToken)
85-
{
86-
try
87-
{
88-
GetMultipleCalls.Add(keys);
89-
var result = new object[keys.Length];
90-
for (var i = 0; i < keys.Length; i++)
91-
{
92-
result[i] = _hashtable[keys[i]];
93-
}
94-
return Task.FromResult<object[]>(result);
95-
}
96-
catch (Exception ex)
97-
{
98-
return Task.FromException<object[]>(ex);
99-
}
100-
}
101-
102-
/// <summary></summary>
103-
public Task PutAsync(object key, object value, CancellationToken cancellationToken)
96+
public override Task PutAsync(object key, object value, CancellationToken cancellationToken)
10497
{
10598
try
10699
{
107100
PutCalls.Add(key);
108101
_hashtable[key] = value;
109102
return Task.CompletedTask;
110103
}
111-
catch (Exception ex)
104+
catch (System.Exception ex)
112105
{
113106
return Task.FromException<object>(ex);
114107
}
115108
}
116109

117-
/// <summary></summary>
118-
public Task RemoveAsync(object key, CancellationToken cancellationToken)
110+
public override Task RemoveAsync(object key, CancellationToken cancellationToken)
119111
{
120112
try
121113
{
122114
_hashtable.Remove(key);
123115
return Task.CompletedTask;
124116
}
125-
catch (Exception ex)
117+
catch (System.Exception ex)
126118
{
127119
return Task.FromException<object>(ex);
128120
}
129121
}
130122

131-
/// <summary></summary>
132-
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
133-
public Task ClearAsync(CancellationToken cancellationToken)
123+
public override Task ClearAsync(CancellationToken cancellationToken)
134124
{
135125
try
136126
{
137127
_hashtable.Clear();
138128
return Task.CompletedTask;
139129
}
140-
catch (Exception ex)
130+
catch (System.Exception ex)
141131
{
142132
return Task.FromException<object>(ex);
143133
}
144134
}
145135

146-
/// <summary></summary>
147-
public Task LockAsync(object key, CancellationToken cancellationToken)
136+
public override Task<object> LockAsync(object key, CancellationToken cancellationToken)
148137
{
149-
return Task.CompletedTask;
150-
// local cache, so we use synchronization
138+
// local cache, no need to actually lock.
139+
return Task.FromResult<object>(null);
151140
}
152141

153-
/// <summary></summary>
154-
public Task UnlockAsync(object key, CancellationToken cancellationToken)
142+
public override Task UnlockAsync(object key, object lockValue, CancellationToken cancellationToken)
155143
{
156144
return Task.CompletedTask;
157-
// local cache, so we use synchronization
145+
// local cache, no need to actually lock.
158146
}
159-
160-
#endregion
161147
}
162148
}

src/NHibernate.Test/Async/NHSpecificTest/NH2898/BinaryFormatterCache.cs

+11-9
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,18 @@
1212
using System.IO;
1313
using System.Runtime.Serialization.Formatters.Binary;
1414
using NHibernate.Cache;
15+
#if !NETFX
1516
using NHibernate.Util;
17+
#endif
1618

1719
namespace NHibernate.Test.NHSpecificTest.NH2898
1820
{
1921
using System.Threading.Tasks;
2022
using System.Threading;
21-
public partial class BinaryFormatterCache : ICache
23+
public partial class BinaryFormatterCache : CacheBase
2224
{
2325

24-
public Task<object> GetAsync(object key, CancellationToken cancellationToken)
26+
public override Task<object> GetAsync(object key, CancellationToken cancellationToken)
2527
{
2628
try
2729
{
@@ -46,7 +48,7 @@ public Task<object> GetAsync(object key, CancellationToken cancellationToken)
4648
}
4749
}
4850

49-
public Task PutAsync(object key, object value, CancellationToken cancellationToken)
51+
public override Task PutAsync(object key, object value, CancellationToken cancellationToken)
5052
{
5153
try
5254
{
@@ -69,7 +71,7 @@ public Task PutAsync(object key, object value, CancellationToken cancellationTok
6971
}
7072
}
7173

72-
public Task RemoveAsync(object key, CancellationToken cancellationToken)
74+
public override Task RemoveAsync(object key, CancellationToken cancellationToken)
7375
{
7476
try
7577
{
@@ -82,7 +84,7 @@ public Task RemoveAsync(object key, CancellationToken cancellationToken)
8284
}
8385
}
8486

85-
public Task ClearAsync(CancellationToken cancellationToken)
87+
public override Task ClearAsync(CancellationToken cancellationToken)
8688
{
8789
try
8890
{
@@ -95,16 +97,16 @@ public Task ClearAsync(CancellationToken cancellationToken)
9597
}
9698
}
9799

98-
public Task LockAsync(object key, CancellationToken cancellationToken)
100+
public override Task<object> LockAsync(object key, CancellationToken cancellationToken)
99101
{
100-
return Task.CompletedTask;
101102
// local cache, so we use synchronization
103+
return Task.FromResult<object>(null);
102104
}
103105

104-
public Task UnlockAsync(object key, CancellationToken cancellationToken)
106+
public override Task UnlockAsync(object key, object lockValue, CancellationToken cancellationToken)
105107
{
106108
return Task.CompletedTask;
107109
// local cache, so we use synchronization
108110
}
109111
}
110-
}
112+
}

src/NHibernate.Test/Async/NHSpecificTest/NH3564/FixtureByCode.cs

+8-8
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ namespace NHibernate.Test.NHSpecificTest.NH3564
2424
{
2525
using System.Threading.Tasks;
2626
using System.Threading;
27-
public partial class MyDummyCache : ICache
27+
public partial class MyDummyCache : CacheBase
2828
{
2929

30-
public Task<object> GetAsync(object key, CancellationToken cancellationToken)
30+
public override Task<object> GetAsync(object key, CancellationToken cancellationToken)
3131
{
3232
try
3333
{
@@ -39,7 +39,7 @@ public Task<object> GetAsync(object key, CancellationToken cancellationToken)
3939
}
4040
}
4141

42-
public Task PutAsync(object key, object value, CancellationToken cancellationToken)
42+
public override Task PutAsync(object key, object value, CancellationToken cancellationToken)
4343
{
4444
try
4545
{
@@ -52,7 +52,7 @@ public Task PutAsync(object key, object value, CancellationToken cancellationTok
5252
}
5353
}
5454

55-
public Task RemoveAsync(object key, CancellationToken cancellationToken)
55+
public override Task RemoveAsync(object key, CancellationToken cancellationToken)
5656
{
5757
try
5858
{
@@ -65,7 +65,7 @@ public Task RemoveAsync(object key, CancellationToken cancellationToken)
6565
}
6666
}
6767

68-
public Task ClearAsync(CancellationToken cancellationToken)
68+
public override Task ClearAsync(CancellationToken cancellationToken)
6969
{
7070
try
7171
{
@@ -78,13 +78,13 @@ public Task ClearAsync(CancellationToken cancellationToken)
7878
}
7979
}
8080

81-
public Task LockAsync(object key, CancellationToken cancellationToken)
81+
public override Task<object> LockAsync(object key, CancellationToken cancellationToken)
8282
{
83-
return Task.CompletedTask;
8483
// local cache, so we use synchronization
84+
return Task.FromResult<object>(null);
8585
}
8686

87-
public Task UnlockAsync(object key, CancellationToken cancellationToken)
87+
public override Task UnlockAsync(object key, object lockValue, CancellationToken cancellationToken)
8888
{
8989
return Task.CompletedTask;
9090
// local cache, so we use synchronization

0 commit comments

Comments
 (0)