Skip to content

Commit e2889f7

Browse files
Remove InternalCache
1 parent ca5a647 commit e2889f7

File tree

6 files changed

+88
-76
lines changed

6 files changed

+88
-76
lines changed

src/NHibernate/Async/Cache/NonstrictReadWriteCache.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public async Task<object> GetAsync(CacheKey key, long txTimestamp, CancellationT
3232
log.Debug("Cache lookup: {0}", key);
3333
}
3434

35-
var result = await (InternalCache.GetAsync(key, cancellationToken)).ConfigureAwait(false);
35+
var result = await (_this.Cache.GetAsync(key, cancellationToken)).ConfigureAwait(false);
3636
if (log.IsDebugEnabled())
3737
{
3838
log.Debug(result != null ? "Cache hit: {0}" : "Cache miss: {0}", key);
@@ -49,7 +49,7 @@ public async Task<object[]> GetManyAsync(CacheKey[] keys, long timestamp, Cancel
4949
log.Debug("Cache lookup: {0}", string.Join(",", keys.AsEnumerable()));
5050
}
5151

52-
var results = await (InternalCache.GetManyAsync(keys, cancellationToken)).ConfigureAwait(false);
52+
var results = await (_this.Cache.GetManyAsync(keys, cancellationToken)).ConfigureAwait(false);
5353
if (log.IsDebugEnabled())
5454
{
5555
log.Debug("Cache hit: {0}", string.Join(",", keys.Where((k, i) => results != null)));
@@ -85,7 +85,7 @@ public async Task<bool[]> PutManyAsync(
8585
}
8686
}
8787

88-
var cache = InternalCache;
88+
var cache = _this.Cache;
8989
var skipKeyIndexes = new HashSet<int>();
9090
if (checkKeys.Any())
9191
{
@@ -138,7 +138,7 @@ public async Task<bool> PutAsync(CacheKey key, object value, long txTimestamp, o
138138
return false;
139139
}
140140

141-
var cache = InternalCache;
141+
var cache = _this.Cache;
142142
if (minimalPut && await (cache.GetAsync(key, cancellationToken)).ConfigureAwait(false) != null)
143143
{
144144
if (log.IsDebugEnabled())
@@ -186,7 +186,7 @@ public Task RemoveAsync(CacheKey key, CancellationToken cancellationToken)
186186
{
187187
log.Debug("Removing: {0}", key);
188188
}
189-
return InternalCache.RemoveAsync(key, cancellationToken);
189+
return _this.Cache.RemoveAsync(key, cancellationToken);
190190
}
191191
catch (Exception ex)
192192
{
@@ -206,7 +206,7 @@ public Task ClearAsync(CancellationToken cancellationToken)
206206
{
207207
log.Debug("Clearing");
208208
}
209-
return InternalCache.ClearAsync(cancellationToken);
209+
return _this.Cache.ClearAsync(cancellationToken);
210210
}
211211
catch (Exception ex)
212212
{
@@ -229,7 +229,7 @@ public Task EvictAsync(CacheKey key, CancellationToken cancellationToken)
229229
{
230230
log.Debug("Invalidating: {0}", key);
231231
}
232-
return InternalCache.RemoveAsync(key, cancellationToken);
232+
return _this.Cache.RemoveAsync(key, cancellationToken);
233233
}
234234
catch (Exception ex)
235235
{
@@ -263,7 +263,7 @@ public Task ReleaseAsync(CacheKey key, ISoftLock @lock, CancellationToken cancel
263263
log.Debug("Invalidating (again): {0}", key);
264264
}
265265

266-
return InternalCache.RemoveAsync(key, cancellationToken);
266+
return _this.Cache.RemoveAsync(key, cancellationToken);
267267
}
268268
catch (Exception ex)
269269
{

src/NHibernate/Async/Cache/ReadOnlyCache.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public partial class ReadOnlyCache : IBatchableCacheConcurrencyStrategy
2424
public async Task<object> GetAsync(CacheKey key, long timestamp, CancellationToken cancellationToken)
2525
{
2626
cancellationToken.ThrowIfCancellationRequested();
27-
var result = await (InternalCache.GetAsync(key, cancellationToken)).ConfigureAwait(false);
27+
var result = await (_this.Cache.GetAsync(key, cancellationToken)).ConfigureAwait(false);
2828
if (log.IsDebugEnabled())
2929
{
3030
log.Debug(result != null ? "Cache hit: {0}" : "Cache miss: {0}", key);
@@ -41,7 +41,7 @@ public async Task<object[]> GetManyAsync(CacheKey[] keys, long timestamp, Cancel
4141
log.Debug("Cache lookup: {0}", string.Join(",", keys.AsEnumerable()));
4242
}
4343

44-
var results = await (InternalCache.GetManyAsync(keys, cancellationToken)).ConfigureAwait(false);
44+
var results = await (_this.Cache.GetManyAsync(keys, cancellationToken)).ConfigureAwait(false);
4545
if (log.IsDebugEnabled())
4646
{
4747
log.Debug("Cache hit: {0}", string.Join(",", keys.Where((k, i) => results[i] != null)));
@@ -93,7 +93,7 @@ public async Task<bool[]> PutManyAsync(
9393
}
9494
}
9595

96-
var cache = InternalCache;
96+
var cache = _this.Cache;
9797
var skipKeyIndexes = new HashSet<int>();
9898
if (checkKeys.Any())
9999
{
@@ -143,7 +143,7 @@ public async Task<bool> PutAsync(CacheKey key, object value, long timestamp, obj
143143
return false;
144144
}
145145

146-
var cache = InternalCache;
146+
var cache = _this.Cache;
147147
if (minimalPut && await (cache.GetAsync(key, cancellationToken)).ConfigureAwait(false) != null)
148148
{
149149
if (log.IsDebugEnabled())
@@ -186,7 +186,7 @@ public Task ClearAsync(CancellationToken cancellationToken)
186186
{
187187
return Task.FromCanceled<object>(cancellationToken);
188188
}
189-
return InternalCache.ClearAsync(cancellationToken);
189+
return _this.Cache.ClearAsync(cancellationToken);
190190
}
191191

192192
public Task RemoveAsync(CacheKey key, CancellationToken cancellationToken)
@@ -195,7 +195,7 @@ public Task RemoveAsync(CacheKey key, CancellationToken cancellationToken)
195195
{
196196
return Task.FromCanceled<object>(cancellationToken);
197197
}
198-
return InternalCache.RemoveAsync(key, cancellationToken);
198+
return _this.Cache.RemoveAsync(key, cancellationToken);
199199
}
200200

201201
/// <summary>

src/NHibernate/Async/Cache/ReadWriteCache.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public partial class ReadWriteCache : IBatchableCacheConcurrencyStrategy
4242
public async Task<object> GetAsync(CacheKey key, long txTimestamp, CancellationToken cancellationToken)
4343
{
4444
cancellationToken.ThrowIfCancellationRequested();
45-
var cache = InternalCache;
45+
var cache = _this.Cache;
4646
cancellationToken.ThrowIfCancellationRequested();
4747
using (await (_asyncReaderWriterLock.ReadLockAsync()).ConfigureAwait(false))
4848
{
@@ -72,7 +72,7 @@ public async Task<object[]> GetManyAsync(CacheKey[] keys, long timestamp, Cancel
7272
{
7373
log.Debug("Cache lookup: {0}", string.Join(",", keys.AsEnumerable()));
7474
}
75-
var cache = InternalCache;
75+
var cache = _this.Cache;
7676
var result = new object[keys.Length];
7777
cancellationToken.ThrowIfCancellationRequested();
7878
using (await (_asyncReaderWriterLock.ReadLockAsync()).ConfigureAwait(false))
@@ -97,7 +97,7 @@ public async Task<object[]> GetManyAsync(CacheKey[] keys, long timestamp, Cancel
9797
public async Task<ISoftLock> LockAsync(CacheKey key, object version, CancellationToken cancellationToken)
9898
{
9999
cancellationToken.ThrowIfCancellationRequested();
100-
var cache = InternalCache;
100+
var cache = _this.Cache;
101101
cancellationToken.ThrowIfCancellationRequested();
102102
using (await (_asyncReaderWriterLock.WriteLockAsync()).ConfigureAwait(false))
103103
{
@@ -143,7 +143,7 @@ public async Task<bool[]> PutManyAsync(
143143
return result;
144144
}
145145

146-
var cache = InternalCache;
146+
var cache = _this.Cache;
147147
cancellationToken.ThrowIfCancellationRequested();
148148
using (await (_asyncReaderWriterLock.WriteLockAsync()).ConfigureAwait(false))
149149
{
@@ -215,7 +215,7 @@ public async Task<bool> PutAsync(CacheKey key, object value, long txTimestamp, o
215215
return false;
216216
}
217217

218-
var cache = InternalCache;
218+
var cache = _this.Cache;
219219
cancellationToken.ThrowIfCancellationRequested();
220220
using (await (_asyncReaderWriterLock.WriteLockAsync()).ConfigureAwait(false))
221221
{
@@ -269,7 +269,7 @@ private Task DecrementLockAsync(object key, CacheLock @lock, CancellationToken c
269269
try
270270
{
271271
//decrement the lock
272-
var cache = InternalCache;
272+
var cache = _this.Cache;
273273
@lock.Unlock(cache.NextTimestamp());
274274
return cache.PutAsync(key, @lock, cancellationToken);
275275
}
@@ -282,7 +282,7 @@ private Task DecrementLockAsync(object key, CacheLock @lock, CancellationToken c
282282
public async Task ReleaseAsync(CacheKey key, ISoftLock clientLock, CancellationToken cancellationToken)
283283
{
284284
cancellationToken.ThrowIfCancellationRequested();
285-
var cache = InternalCache;
285+
var cache = _this.Cache;
286286
cancellationToken.ThrowIfCancellationRequested();
287287
using (await (_asyncReaderWriterLock.WriteLockAsync()).ConfigureAwait(false))
288288
{
@@ -320,7 +320,7 @@ internal Task HandleLockExpiryAsync(object key, CancellationToken cancellationTo
320320
try
321321
{
322322
log.Warn("An item was expired by the cache while it was locked (increase your cache timeout): {0}", key);
323-
var cache = InternalCache;
323+
var cache = _this.Cache;
324324
long ts = cache.NextTimestamp() + cache.Timeout;
325325
// create new lock that times out immediately
326326
CacheLock @lock = CacheLock.Create(ts, NextLockId(), null);
@@ -339,7 +339,7 @@ public Task ClearAsync(CancellationToken cancellationToken)
339339
{
340340
return Task.FromCanceled<object>(cancellationToken);
341341
}
342-
return InternalCache.ClearAsync(cancellationToken);
342+
return _this.Cache.ClearAsync(cancellationToken);
343343
}
344344

345345
public Task RemoveAsync(CacheKey key, CancellationToken cancellationToken)
@@ -348,7 +348,7 @@ public Task RemoveAsync(CacheKey key, CancellationToken cancellationToken)
348348
{
349349
return Task.FromCanceled<object>(cancellationToken);
350350
}
351-
return InternalCache.RemoveAsync(key, cancellationToken);
351+
return _this.Cache.RemoveAsync(key, cancellationToken);
352352
}
353353

354354
/// <summary>
@@ -358,7 +358,7 @@ public Task RemoveAsync(CacheKey key, CancellationToken cancellationToken)
358358
public async Task<bool> AfterUpdateAsync(CacheKey key, object value, object version, ISoftLock clientLock, CancellationToken cancellationToken)
359359
{
360360
cancellationToken.ThrowIfCancellationRequested();
361-
var cache = InternalCache;
361+
var cache = _this.Cache;
362362
cancellationToken.ThrowIfCancellationRequested();
363363
using (await (_asyncReaderWriterLock.WriteLockAsync()).ConfigureAwait(false))
364364
{
@@ -407,7 +407,7 @@ public async Task<bool> AfterUpdateAsync(CacheKey key, object value, object vers
407407
public async Task<bool> AfterInsertAsync(CacheKey key, object value, object version, CancellationToken cancellationToken)
408408
{
409409
cancellationToken.ThrowIfCancellationRequested();
410-
var cache = InternalCache;
410+
var cache = _this.Cache;
411411
cancellationToken.ThrowIfCancellationRequested();
412412
using (await (_asyncReaderWriterLock.WriteLockAsync()).ConfigureAwait(false))
413413
{

src/NHibernate/Cache/NonstrictReadWriteCache.cs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,19 @@ public partial class NonstrictReadWriteCache : IBatchableCacheConcurrencyStrateg
1818
{
1919
private static readonly INHibernateLogger log = NHibernateLogger.For(typeof(NonstrictReadWriteCache));
2020

21+
// 6.0 TODO : remove
22+
private readonly IBatchableCacheConcurrencyStrategy _this;
2123
private CacheBase _cache;
2224
private bool _isDestroyed;
2325

26+
/// <summary>
27+
/// Default constructor.
28+
/// </summary>
29+
public NonstrictReadWriteCache()
30+
{
31+
_this = this;
32+
}
33+
2434
/// <summary>
2535
/// Gets the cache region name.
2636
/// </summary>
@@ -38,21 +48,15 @@ public ICache Cache
3848
set { _cache = value?.AsCacheBase(); }
3949
}
4050

41-
// 6.0 TODO: Rename to Cache and make public (possible breaking change for reader when null).
42-
private CacheBase InternalCache
51+
// 6.0 TODO: implement implicitly
52+
CacheBase IBatchableCacheConcurrencyStrategy.Cache
4353
{
4454
get
4555
{
4656
if (_cache == null || _isDestroyed)
4757
throw new InvalidOperationException(_isDestroyed ? "The cache has already been destroyed" : "The concrete cache is not defined");
4858
return _cache;
4959
}
50-
}
51-
52-
// 6.0 TODO: remove
53-
CacheBase IBatchableCacheConcurrencyStrategy.Cache
54-
{
55-
get => _cache;
5660
set => _cache = value;
5761
}
5862

@@ -66,7 +70,7 @@ public object Get(CacheKey key, long txTimestamp)
6670
log.Debug("Cache lookup: {0}", key);
6771
}
6872

69-
var result = InternalCache.Get(key);
73+
var result = _this.Cache.Get(key);
7074
if (log.IsDebugEnabled())
7175
{
7276
log.Debug(result != null ? "Cache hit: {0}" : "Cache miss: {0}", key);
@@ -82,7 +86,7 @@ public object[] GetMany(CacheKey[] keys, long timestamp)
8286
log.Debug("Cache lookup: {0}", string.Join(",", keys.AsEnumerable()));
8387
}
8488

85-
var results = InternalCache.GetMany(keys);
89+
var results = _this.Cache.GetMany(keys);
8690
if (log.IsDebugEnabled())
8791
{
8892
log.Debug("Cache hit: {0}", string.Join(",", keys.Where((k, i) => results != null)));
@@ -117,7 +121,7 @@ public bool[] PutMany(
117121
}
118122
}
119123

120-
var cache = InternalCache;
124+
var cache = _this.Cache;
121125
var skipKeyIndexes = new HashSet<int>();
122126
if (checkKeys.Any())
123127
{
@@ -169,7 +173,7 @@ public bool Put(CacheKey key, object value, long txTimestamp, object version, IC
169173
return false;
170174
}
171175

172-
var cache = InternalCache;
176+
var cache = _this.Cache;
173177
if (minimalPut && cache.Get(key) != null)
174178
{
175179
if (log.IsDebugEnabled())
@@ -200,7 +204,7 @@ public void Remove(CacheKey key)
200204
{
201205
log.Debug("Removing: {0}", key);
202206
}
203-
InternalCache.Remove(key);
207+
_this.Cache.Remove(key);
204208
}
205209

206210
public void Clear()
@@ -209,7 +213,7 @@ public void Clear()
209213
{
210214
log.Debug("Clearing");
211215
}
212-
InternalCache.Clear();
216+
_this.Cache.Clear();
213217
}
214218

215219
public void Destroy()
@@ -229,7 +233,7 @@ public void Evict(CacheKey key)
229233
{
230234
log.Debug("Invalidating: {0}", key);
231235
}
232-
InternalCache.Remove(key);
236+
_this.Cache.Remove(key);
233237
}
234238

235239
/// <summary>
@@ -259,7 +263,7 @@ public void Release(CacheKey key, ISoftLock @lock)
259263
log.Debug("Invalidating (again): {0}", key);
260264
}
261265

262-
InternalCache.Remove(key);
266+
_this.Cache.Remove(key);
263267
}
264268

265269
/// <summary>

0 commit comments

Comments
 (0)