Skip to content

Commit 7d0c21e

Browse files
fixup! Replace ICache interface by a CacheBase class
Remove a field and rename a property
1 parent 459e840 commit 7d0c21e

9 files changed

+83
-81
lines changed

src/NHibernate/Async/Cache/ICacheConcurrencyStrategy.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
//------------------------------------------------------------------------------
99

1010

11-
using System;
1211
using System.Collections;
1312
using NHibernate.Cache.Access;
1413
using NHibernate.Cache.Entry;
@@ -150,7 +149,7 @@ public static Task<object[]> GetManyAsync(this ICacheConcurrencyStrategy cache,
150149
.CastOrThrow<IBatchableCacheConcurrencyStrategy>(cache, "batching")
151150
.GetManyAsync(keys, timestamp, cancellationToken);
152151
}
153-
catch (Exception ex)
152+
catch (System.Exception ex)
154153
{
155154
return Task.FromException<object[]>(ex);
156155
}

src/NHibernate/Async/Cache/NonstrictReadWriteCache.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public async Task<object[]> GetManyAsync(CacheKey[] keys, long timestamp, Cancel
5151
{
5252
log.Debug("Cache lookup: {0}", string.Join(",", keys.AsEnumerable()));
5353
}
54-
var results = await (_batchableCache.GetManyAsync(keys.Select(o => (object) o).ToArray(), cancellationToken)).ConfigureAwait(false);
54+
var results = await (_cache.GetManyAsync(keys.Select(o => (object) o).ToArray(), cancellationToken)).ConfigureAwait(false);
5555
if (!log.IsDebugEnabled())
5656
{
5757
return results;
@@ -91,7 +91,7 @@ public async Task<bool[]> PutManyAsync(
9191
var skipKeyIndexes = new HashSet<int>();
9292
if (checkKeys.Any())
9393
{
94-
var objects = await (_batchableCache.GetManyAsync(checkKeys.ToArray(), cancellationToken)).ConfigureAwait(false);
94+
var objects = await (_cache.GetManyAsync(checkKeys.ToArray(), cancellationToken)).ConfigureAwait(false);
9595
for (var i = 0; i < objects.Length; i++)
9696
{
9797
if (objects[i] != null)
@@ -123,7 +123,7 @@ public async Task<bool[]> PutManyAsync(
123123
putValues[j++] = values[i];
124124
result[i] = true;
125125
}
126-
await (_batchableCache.PutManyAsync(putKeys, putValues, cancellationToken)).ConfigureAwait(false);
126+
await (_cache.PutManyAsync(putKeys, putValues, cancellationToken)).ConfigureAwait(false);
127127
return result;
128128
}
129129

src/NHibernate/Async/Cache/ReadOnlyCache.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public async Task<object[]> GetManyAsync(CacheKey[] keys, long timestamp, Cancel
3939
{
4040
log.Debug("Cache lookup: {0}", string.Join(",", keys.AsEnumerable()));
4141
}
42-
var results = await (_batchableCache.GetManyAsync(keys.Select(o => (object) o).ToArray(), cancellationToken)).ConfigureAwait(false);
42+
var results = await (_cache.GetManyAsync(keys.Select(o => (object) o).ToArray(), cancellationToken)).ConfigureAwait(false);
4343
if (!log.IsDebugEnabled())
4444
{
4545
return results;
@@ -95,7 +95,7 @@ public async Task<bool[]> PutManyAsync(
9595
var skipKeyIndexes = new HashSet<int>();
9696
if (checkKeys.Any())
9797
{
98-
var objects = await (_batchableCache.GetManyAsync(checkKeys.Select(o => (object) o).ToArray(), cancellationToken)).ConfigureAwait(false);
98+
var objects = await (_cache.GetManyAsync(checkKeys.Select(o => (object) o).ToArray(), cancellationToken)).ConfigureAwait(false);
9999
for (var i = 0; i < objects.Length; i++)
100100
{
101101
if (objects[i] != null)
@@ -127,7 +127,7 @@ public async Task<bool[]> PutManyAsync(
127127
putValues[j++] = values[i];
128128
result[i] = true;
129129
}
130-
await (_batchableCache.PutManyAsync(putKeys, putValues, cancellationToken)).ConfigureAwait(false);
130+
await (_cache.PutManyAsync(putKeys, putValues, cancellationToken)).ConfigureAwait(false);
131131
return result;
132132
}
133133

src/NHibernate/Async/Cache/ReadWriteCache.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public async Task<object[]> GetManyAsync(CacheKey[] keys, long timestamp, Cancel
100100
var result = new object[keys.Length];
101101
using (await _lockObjectAsync.LockAsync())
102102
{
103-
var lockables = await (_cacheBase.GetManyAsync(keys.Select(o => (object) o).ToArray(), cancellationToken)).ConfigureAwait(false);
103+
var lockables = await (_cache.GetManyAsync(keys.Select(o => (object) o).ToArray(), cancellationToken)).ConfigureAwait(false);
104104
for (var i = 0; i < lockables.Length; i++)
105105
{
106106
var lockable = (ILockable) lockables[i];
@@ -143,7 +143,7 @@ public async Task<ISoftLock> LockAsync(CacheKey key, object version, Cancellatio
143143
log.Debug("Invalidating: {0}", key);
144144
}
145145

146-
var lockValue = await (_cacheBase.LockAsync(key, cancellationToken)).ConfigureAwait(false);
146+
var lockValue = await (_cache.LockAsync(key, cancellationToken)).ConfigureAwait(false);
147147
try
148148
{
149149
ILockable lockable = (ILockable) await (Cache.GetAsync(key, cancellationToken)).ConfigureAwait(false);
@@ -156,7 +156,7 @@ public async Task<ISoftLock> LockAsync(CacheKey key, object version, Cancellatio
156156
}
157157
finally
158158
{
159-
await (_cacheBase.UnlockAsync(key, lockValue, cancellationToken)).ConfigureAwait(false);
159+
await (_cache.UnlockAsync(key, lockValue, cancellationToken)).ConfigureAwait(false);
160160
}
161161
}
162162
}
@@ -187,11 +187,11 @@ public async Task<bool[]> PutManyAsync(
187187
log.Debug("Caching: {0}", string.Join(",", keys.AsEnumerable()));
188188
}
189189
var keysArr = keys.Cast<object>().ToArray();
190-
var lockValue = await (_cacheBase.LockManyAsync(keysArr, cancellationToken)).ConfigureAwait(false);
190+
var lockValue = await (_cache.LockManyAsync(keysArr, cancellationToken)).ConfigureAwait(false);
191191
try
192192
{
193193
var putBatch = new Dictionary<object, object>();
194-
var lockables = await (_cacheBase.GetManyAsync(keysArr, cancellationToken)).ConfigureAwait(false);
194+
var lockables = await (_cache.GetManyAsync(keysArr, cancellationToken)).ConfigureAwait(false);
195195
for (var i = 0; i < keys.Length; i++)
196196
{
197197
var key = keys[i];
@@ -201,7 +201,7 @@ public async Task<bool[]> PutManyAsync(
201201
lockable.IsPuttable(timestamp, version, versionComparers[i]);
202202
if (puttable)
203203
{
204-
putBatch.Add(key, CachedItem.Create(values[i], cache.NextTimestamp(), version));
204+
putBatch.Add(key, CachedItem.Create(values[i], Cache.NextTimestamp(), version));
205205
if (log.IsDebugEnabled())
206206
{
207207
log.Debug("Cached: {0}", key);
@@ -227,12 +227,12 @@ public async Task<bool[]> PutManyAsync(
227227

228228
if (putBatch.Count > 0)
229229
{
230-
await (_cacheBase.PutManyAsync(putBatch.Keys.ToArray(), putBatch.Values.ToArray(), cancellationToken)).ConfigureAwait(false);
230+
await (_cache.PutManyAsync(putBatch.Keys.ToArray(), putBatch.Values.ToArray(), cancellationToken)).ConfigureAwait(false);
231231
}
232232
}
233233
finally
234234
{
235-
await (_cacheBase.UnlockManyAsync(keysArr, lockValue, cancellationToken)).ConfigureAwait(false);
235+
await (_cache.UnlockManyAsync(keysArr, lockValue, cancellationToken)).ConfigureAwait(false);
236236
}
237237
}
238238
return result;
@@ -262,7 +262,7 @@ public async Task<bool> PutAsync(CacheKey key, object value, long txTimestamp, o
262262
log.Debug("Caching: {0}", key);
263263
}
264264

265-
var lockValue = await (_cacheBase.LockAsync(key, cancellationToken)).ConfigureAwait(false);
265+
var lockValue = await (_cache.LockAsync(key, cancellationToken)).ConfigureAwait(false);
266266
try
267267
{
268268
ILockable lockable = (ILockable) await (Cache.GetAsync(key, cancellationToken)).ConfigureAwait(false);
@@ -297,7 +297,7 @@ public async Task<bool> PutAsync(CacheKey key, object value, long txTimestamp, o
297297
}
298298
finally
299299
{
300-
await (_cacheBase.UnlockAsync(key, lockValue, cancellationToken)).ConfigureAwait(false);
300+
await (_cache.UnlockAsync(key, lockValue, cancellationToken)).ConfigureAwait(false);
301301
}
302302
}
303303
}
@@ -333,7 +333,7 @@ public async Task ReleaseAsync(CacheKey key, ISoftLock clientLock, CancellationT
333333
log.Debug("Releasing: {0}", key);
334334
}
335335

336-
var lockValue = await (_cacheBase.LockAsync(key, cancellationToken)).ConfigureAwait(false);
336+
var lockValue = await (_cache.LockAsync(key, cancellationToken)).ConfigureAwait(false);
337337
try
338338
{
339339
ILockable lockable = (ILockable) await (Cache.GetAsync(key, cancellationToken)).ConfigureAwait(false);
@@ -348,7 +348,7 @@ public async Task ReleaseAsync(CacheKey key, ISoftLock clientLock, CancellationT
348348
}
349349
finally
350350
{
351-
await (_cacheBase.UnlockAsync(key, lockValue, cancellationToken)).ConfigureAwait(false);
351+
await (_cache.UnlockAsync(key, lockValue, cancellationToken)).ConfigureAwait(false);
352352
}
353353
}
354354
}
@@ -406,7 +406,7 @@ public async Task<bool> AfterUpdateAsync(CacheKey key, object value, object vers
406406
log.Debug("Updating: {0}", key);
407407
}
408408

409-
var lockValue = await (_cacheBase.LockAsync(key, cancellationToken)).ConfigureAwait(false);
409+
var lockValue = await (_cache.LockAsync(key, cancellationToken)).ConfigureAwait(false);
410410
try
411411
{
412412
ILockable lockable = (ILockable) await (Cache.GetAsync(key, cancellationToken)).ConfigureAwait(false);
@@ -438,7 +438,7 @@ public async Task<bool> AfterUpdateAsync(CacheKey key, object value, object vers
438438
}
439439
finally
440440
{
441-
await (_cacheBase.UnlockAsync(key, lockValue, cancellationToken)).ConfigureAwait(false);
441+
await (_cache.UnlockAsync(key, lockValue, cancellationToken)).ConfigureAwait(false);
442442
}
443443
}
444444
}
@@ -453,7 +453,7 @@ public async Task<bool> AfterInsertAsync(CacheKey key, object value, object vers
453453
log.Debug("Inserting: {0}", key);
454454
}
455455

456-
var lockValue = await (_cacheBase.LockAsync(key, cancellationToken)).ConfigureAwait(false);
456+
var lockValue = await (_cache.LockAsync(key, cancellationToken)).ConfigureAwait(false);
457457
try
458458
{
459459

@@ -474,7 +474,7 @@ public async Task<bool> AfterInsertAsync(CacheKey key, object value, object vers
474474
}
475475
finally
476476
{
477-
await (_cacheBase.UnlockAsync(key, lockValue, cancellationToken)).ConfigureAwait(false);
477+
await (_cache.UnlockAsync(key, lockValue, cancellationToken)).ConfigureAwait(false);
478478
}
479479
}
480480
}

src/NHibernate/Cache/IBatchableCacheConcurrencyStrategy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ bool[] PutMany(CacheKey[] keys, object[] values, long timestamp, object[] versio
4747
bool[] minimalPuts);
4848

4949
// 6.0 TODO: remove for using ICacheConcurrencyStrategy.Cache re-typed CacheBase instead
50-
CacheBase CacheBase { get; }
50+
new CacheBase Cache { get; set; }
5151
}
5252
}

src/NHibernate/Cache/ICacheConcurrencyStrategy.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System;
21
using System.Collections;
32
using NHibernate.Cache.Access;
43
using NHibernate.Cache.Entry;
@@ -198,15 +197,15 @@ public static bool[] PutMany(this ICacheConcurrencyStrategy cache, CacheKey[] ke
198197
internal static bool PreferMultipleGet(this ICacheConcurrencyStrategy cache)
199198
{
200199
if (cache is IBatchableCacheConcurrencyStrategy batchableCache)
201-
return batchableCache.CacheBase.PreferMultipleGet;
200+
return batchableCache.Cache.PreferMultipleGet;
202201
return false;
203202
}
204203

205204
// 6.0 TODO: remove
206205
internal static CacheBase GetCacheBase(this ICacheConcurrencyStrategy cache)
207206
{
208207
if (cache is IBatchableCacheConcurrencyStrategy batchableCache)
209-
return batchableCache.CacheBase;
208+
return batchableCache.Cache;
210209
var concreteCache = cache.Cache;
211210
if (concreteCache == null)
212211
return null;

src/NHibernate/Cache/NonstrictReadWriteCache.cs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@ namespace NHibernate.Cache
1616
/// </summary>
1717
public partial class NonstrictReadWriteCache : IBatchableCacheConcurrencyStrategy
1818
{
19-
#pragma warning disable 618
20-
private ICache cache;
21-
#pragma warning restore 618
22-
private CacheBase _batchableCache;
23-
2419
private static readonly INHibernateLogger log = NHibernateLogger.For(typeof(NonstrictReadWriteCache));
2520

21+
// 6.0 TODO: remove
22+
private CacheBase _cache;
23+
2624
/// <summary>
2725
/// Gets the cache region name.
2826
/// </summary>
@@ -31,21 +29,24 @@ public string RegionName
3129
get { return Cache.RegionName; }
3230
}
3331

34-
// 6.0 TODO: type as CacheBase instead and switch to auto-property
32+
// 6.0 TODO: remove
3533
#pragma warning disable 618
3634
public ICache Cache
3735
#pragma warning restore 618
3836
{
39-
get { return cache; }
37+
get { return _cache; }
4038
set
4139
{
42-
cache = value;
43-
_batchableCache = value as CacheBase ?? new ObsoleteCacheWrapper(value);
40+
_cache = value as CacheBase ?? new ObsoleteCacheWrapper(value);
4441
}
4542
}
4643

47-
// 6.0 TODO: remove
48-
public CacheBase CacheBase => _batchableCache;
44+
// 6.0 TODO: make implicit and switch to auto-property
45+
CacheBase IBatchableCacheConcurrencyStrategy.Cache
46+
{
47+
get => _cache;
48+
set => _cache = value;
49+
}
4950

5051
/// <summary>
5152
/// Get the most recent version, if available.
@@ -75,7 +76,7 @@ public object[] GetMany(CacheKey[] keys, long timestamp)
7576
{
7677
log.Debug("Cache lookup: {0}", string.Join(",", keys.AsEnumerable()));
7778
}
78-
var results = _batchableCache.GetMany(keys.Select(o => (object) o).ToArray());
79+
var results = _cache.GetMany(keys.Select(o => (object) o).ToArray());
7980
if (!log.IsDebugEnabled())
8081
{
8182
return results;
@@ -114,7 +115,7 @@ public bool[] PutMany(
114115
var skipKeyIndexes = new HashSet<int>();
115116
if (checkKeys.Any())
116117
{
117-
var objects = _batchableCache.GetMany(checkKeys.ToArray());
118+
var objects = _cache.GetMany(checkKeys.ToArray());
118119
for (var i = 0; i < objects.Length; i++)
119120
{
120121
if (objects[i] != null)
@@ -146,7 +147,7 @@ public bool[] PutMany(
146147
putValues[j++] = values[i];
147148
result[i] = true;
148149
}
149-
_batchableCache.PutMany(putKeys, putValues);
150+
_cache.PutMany(putKeys, putValues);
150151
return result;
151152
}
152153

src/NHibernate/Cache/ReadOnlyCache.cs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@ namespace NHibernate.Cache
1111
/// </summary>
1212
public partial class ReadOnlyCache : IBatchableCacheConcurrencyStrategy
1313
{
14-
#pragma warning disable 618
15-
private ICache cache;
16-
#pragma warning restore 618
17-
private CacheBase _batchableCache;
1814
private static readonly INHibernateLogger log = NHibernateLogger.For(typeof(ReadOnlyCache));
1915

16+
// 6.0 TODO: remove
17+
private CacheBase _cache;
18+
2019
/// <summary>
2120
/// Gets the cache region name.
2221
/// </summary>
@@ -25,21 +24,24 @@ public string RegionName
2524
get { return Cache.RegionName; }
2625
}
2726

28-
// 6.0 TODO: type as CacheBase instead and switch to autoproperty
27+
// 6.0 TODO: remove
2928
#pragma warning disable 618
3029
public ICache Cache
3130
#pragma warning restore 618
3231
{
33-
get { return cache; }
32+
get { return _cache; }
3433
set
3534
{
36-
cache = value;
37-
_batchableCache = value as CacheBase ?? new ObsoleteCacheWrapper(value);
35+
_cache = value as CacheBase ?? new ObsoleteCacheWrapper(value);
3836
}
3937
}
4038

41-
// 6.0 TODO: remove
42-
public CacheBase CacheBase => _batchableCache;
39+
// 6.0 TODO: make implicit and switch to auto-property
40+
CacheBase IBatchableCacheConcurrencyStrategy.Cache
41+
{
42+
get => _cache;
43+
set => _cache = value;
44+
}
4345

4446
public object Get(CacheKey key, long timestamp)
4547
{
@@ -57,7 +59,7 @@ public object[] GetMany(CacheKey[] keys, long timestamp)
5759
{
5860
log.Debug("Cache lookup: {0}", string.Join(",", keys.AsEnumerable()));
5961
}
60-
var results = _batchableCache.GetMany(keys.Select(o => (object) o).ToArray());
62+
var results = _cache.GetMany(keys.Select(o => (object) o).ToArray());
6163
if (!log.IsDebugEnabled())
6264
{
6365
return results;
@@ -102,7 +104,7 @@ public bool[] PutMany(
102104
var skipKeyIndexes = new HashSet<int>();
103105
if (checkKeys.Any())
104106
{
105-
var objects = _batchableCache.GetMany(checkKeys.Select(o => (object) o).ToArray());
107+
var objects = _cache.GetMany(checkKeys.Select(o => (object) o).ToArray());
106108
for (var i = 0; i < objects.Length; i++)
107109
{
108110
if (objects[i] != null)
@@ -134,7 +136,7 @@ public bool[] PutMany(
134136
putValues[j++] = values[i];
135137
result[i] = true;
136138
}
137-
_batchableCache.PutMany(putKeys, putValues);
139+
_cache.PutMany(putKeys, putValues);
138140
return result;
139141
}
140142

0 commit comments

Comments
 (0)