From 378cd35134e1ed55ac142e4968c8af5ba04eb505 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Delaporte?= <12201973+fredericdelaporte@users.noreply.github.com> Date: Tue, 27 Nov 2018 13:14:04 +0100 Subject: [PATCH 1/3] Upgrade to NHibernate 5.2.0 Done with binary breaking changes --- AsyncGenerator.yml | 253 ------------------ ...e.Caches.CoreDistributedCache.Tests.csproj | 3 - .../Async/CoreDistributedCache.cs | 19 +- .../CoreDistributedCache.cs | 23 +- .../CoreDistributedCacheProvider.cs | 4 +- ...bernate.Caches.CoreDistributedCache.csproj | 2 +- .../Async/CoreMemoryCache.cs | 145 ---------- .../CoreMemoryCache.cs | 27 +- .../CoreMemoryCacheProvider.cs | 2 + .../NHibernate.Caches.CoreMemoryCache.csproj | 2 +- .../Async/MemCacheClient.cs | 150 ----------- .../MemCacheClient.cs | 25 +- .../MemCacheProvider.cs | 2 + .../NHibernate.Caches.EnyimMemcached.csproj | 2 +- .../Async/MemCacheClient.cs | 148 ---------- .../MemCacheClient.cs | 25 +- .../MemCacheProvider.cs | 2 + .../NHibernate.Caches.MemCache.csproj | 2 +- .../CacheFixture.cs | 4 +- NHibernate.Caches.Common.Tests/Fixture.cs | 4 +- .../NHibernate.Caches.Common.Tests.csproj | 2 +- .../Async/PrevalenceCache.cs | 133 --------- .../NHibernate.Caches.Prevalence.csproj | 2 +- .../PrevalenceCache.cs | 25 +- .../PrevalenceCacheProvider.cs | 2 + .../RtMemoryCacheProviderFixture.cs | 2 +- .../Async/RtMemoryCache.cs | 144 ---------- .../NHibernate.Caches.RtMemoryCache.csproj | 2 +- .../RtMemoryCache.cs | 23 +- .../RtMemoryCacheProvider.cs | 2 + .../Async/SharedCacheClient.cs | 142 ---------- .../NHibernate.Caches.SharedCache.csproj | 2 +- .../SharedCacheClient.cs | 22 +- .../SharedCacheProvider.cs | 2 + .../Async/SysCache.cs | 145 ---------- .../NHibernate.Caches.SysCache.csproj | 2 +- .../NHibernate.Caches.SysCache/SysCache.cs | 23 +- .../SysCacheProvider.cs | 2 + .../SysCacheProviderFixture.cs | 2 +- .../Async/SysCacheRegion.cs | 154 ----------- .../NHibernate.Caches.SysCache2.csproj | 2 +- .../SysCacheProvider.cs | 9 +- .../SysCacheRegion.cs | 25 +- .../Async/VelocityClient.cs | 143 ---------- .../NHibernate.Caches.Velocity.csproj | 2 +- .../VelocityClient.cs | 28 +- .../VelocityProvider.cs | 2 + 47 files changed, 179 insertions(+), 1709 deletions(-) delete mode 100644 CoreMemoryCache/NHibernate.Caches.CoreMemoryCache/Async/CoreMemoryCache.cs delete mode 100644 EnyimMemcached/NHibernate.Caches.EnyimMemcached/Async/MemCacheClient.cs delete mode 100644 MemCache/NHibernate.Caches.MemCache/Async/MemCacheClient.cs delete mode 100644 Prevalence/NHibernate.Caches.Prevalence/Async/PrevalenceCache.cs delete mode 100644 RtMemoryCache/NHibernate.Caches.RtMemoryCache/Async/RtMemoryCache.cs delete mode 100644 SharedCache/NHibernate.Caches.SharedCache/Async/SharedCacheClient.cs delete mode 100644 SysCache/NHibernate.Caches.SysCache/Async/SysCache.cs delete mode 100644 SysCache2/NHibernate.Caches.SysCache2/Async/SysCacheRegion.cs delete mode 100644 Velocity/NHibernate.Caches.Velocity/Async/VelocityClient.cs diff --git a/AsyncGenerator.yml b/AsyncGenerator.yml index 9489bf4e..c5118e76 100644 --- a/AsyncGenerator.yml +++ b/AsyncGenerator.yml @@ -28,259 +28,6 @@ registerPlugin: - type: AsyncGenerator.Core.Plugins.EmptyRegionRemover assemblyName: AsyncGenerator.Core -- filePath: CoreMemoryCache\NHibernate.Caches.CoreMemoryCache\NHibernate.Caches.CoreMemoryCache.csproj - targetFramework: net461 - concurrentRun: true - applyChanges: true - analyzation: - methodConversion: - - conversion: Ignore - hasAttributeName: ObsoleteAttribute - callForwarding: true - cancellationTokens: - guards: true - methodParameter: - - anyInterfaceRule: PubliclyExposedType - parameter: Optional - - parameter: Optional - rule: PubliclyExposedType - - parameter: Required - scanMethodBody: true - scanForMissingAsyncMembers: - - all: true - transformation: - configureAwaitArgument: false - localFunctions: true - asyncLock: - type: NHibernate.Util.AsyncLock - methodName: LockAsync - registerPlugin: - - type: AsyncGenerator.Core.Plugins.EmptyRegionRemover - assemblyName: AsyncGenerator.Core -- filePath: EnyimMemcached\NHibernate.Caches.EnyimMemcached\NHibernate.Caches.EnyimMemcached.csproj - concurrentRun: true - applyChanges: true - analyzation: - methodConversion: - - conversion: Ignore - hasAttributeName: ObsoleteAttribute - callForwarding: true - cancellationTokens: - guards: true - methodParameter: - - anyInterfaceRule: PubliclyExposedType - parameter: Optional - - parameter: Optional - rule: PubliclyExposedType - - parameter: Required - scanMethodBody: true - scanForMissingAsyncMembers: - - all: true - transformation: - configureAwaitArgument: false - localFunctions: true - asyncLock: - type: NHibernate.Util.AsyncLock - methodName: LockAsync - registerPlugin: - - type: AsyncGenerator.Core.Plugins.EmptyRegionRemover - assemblyName: AsyncGenerator.Core -- filePath: MemCache\NHibernate.Caches.MemCache\NHibernate.Caches.MemCache.csproj - concurrentRun: true - applyChanges: true - analyzation: - methodConversion: - - conversion: Ignore - hasAttributeName: ObsoleteAttribute - callForwarding: true - cancellationTokens: - guards: true - methodParameter: - - anyInterfaceRule: PubliclyExposedType - parameter: Optional - - parameter: Optional - rule: PubliclyExposedType - - parameter: Required - scanMethodBody: true - scanForMissingAsyncMembers: - - all: true - transformation: - configureAwaitArgument: false - localFunctions: true - asyncLock: - type: NHibernate.Util.AsyncLock - methodName: LockAsync - registerPlugin: - - type: AsyncGenerator.Core.Plugins.EmptyRegionRemover - assemblyName: AsyncGenerator.Core -- filePath: Prevalence\NHibernate.Caches.Prevalence\NHibernate.Caches.Prevalence.csproj - concurrentRun: true - applyChanges: true - analyzation: - methodConversion: - - conversion: Ignore - hasAttributeName: ObsoleteAttribute - callForwarding: true - cancellationTokens: - guards: true - methodParameter: - - anyInterfaceRule: PubliclyExposedType - parameter: Optional - - parameter: Optional - rule: PubliclyExposedType - - parameter: Required - scanMethodBody: true - scanForMissingAsyncMembers: - - all: true - transformation: - configureAwaitArgument: false - localFunctions: true - asyncLock: - type: NHibernate.Util.AsyncLock - methodName: LockAsync - registerPlugin: - - type: AsyncGenerator.Core.Plugins.EmptyRegionRemover - assemblyName: AsyncGenerator.Core -- filePath: RtMemoryCache\NHibernate.Caches.RtMemoryCache\NHibernate.Caches.RtMemoryCache.csproj - concurrentRun: true - applyChanges: true - analyzation: - methodConversion: - - conversion: Ignore - hasAttributeName: ObsoleteAttribute - callForwarding: true - cancellationTokens: - guards: true - methodParameter: - - anyInterfaceRule: PubliclyExposedType - parameter: Optional - - parameter: Optional - rule: PubliclyExposedType - - parameter: Required - scanMethodBody: true - scanForMissingAsyncMembers: - - all: true - transformation: - configureAwaitArgument: false - localFunctions: true - asyncLock: - type: NHibernate.Util.AsyncLock - methodName: LockAsync - registerPlugin: - - type: AsyncGenerator.Core.Plugins.EmptyRegionRemover - assemblyName: AsyncGenerator.Core -- filePath: SharedCache\NHibernate.Caches.SharedCache\NHibernate.Caches.SharedCache.csproj - concurrentRun: true - applyChanges: true - analyzation: - methodConversion: - - conversion: Ignore - hasAttributeName: ObsoleteAttribute - callForwarding: true - cancellationTokens: - guards: true - methodParameter: - - anyInterfaceRule: PubliclyExposedType - parameter: Optional - - parameter: Optional - rule: PubliclyExposedType - - parameter: Required - scanMethodBody: true - scanForMissingAsyncMembers: - - all: true - transformation: - configureAwaitArgument: false - localFunctions: true - asyncLock: - type: NHibernate.Util.AsyncLock - methodName: LockAsync - registerPlugin: - - type: AsyncGenerator.Core.Plugins.EmptyRegionRemover - assemblyName: AsyncGenerator.Core -- filePath: SysCache\NHibernate.Caches.SysCache\NHibernate.Caches.SysCache.csproj - concurrentRun: true - applyChanges: true - analyzation: - methodConversion: - - conversion: Ignore - hasAttributeName: ObsoleteAttribute - callForwarding: true - cancellationTokens: - guards: true - methodParameter: - - anyInterfaceRule: PubliclyExposedType - parameter: Optional - - parameter: Optional - rule: PubliclyExposedType - - parameter: Required - scanMethodBody: true - scanForMissingAsyncMembers: - - all: true - transformation: - configureAwaitArgument: false - localFunctions: true - asyncLock: - type: NHibernate.Util.AsyncLock - methodName: LockAsync - registerPlugin: - - type: AsyncGenerator.Core.Plugins.EmptyRegionRemover - assemblyName: AsyncGenerator.Core -- filePath: SysCache2\NHibernate.Caches.SysCache2\NHibernate.Caches.SysCache2.csproj - concurrentRun: true - applyChanges: true - analyzation: - methodConversion: - - conversion: Ignore - hasAttributeName: ObsoleteAttribute - callForwarding: true - cancellationTokens: - guards: true - methodParameter: - - anyInterfaceRule: PubliclyExposedType - parameter: Optional - - parameter: Optional - rule: PubliclyExposedType - - parameter: Required - scanMethodBody: true - scanForMissingAsyncMembers: - - all: true - transformation: - configureAwaitArgument: false - localFunctions: true - asyncLock: - type: NHibernate.Util.AsyncLock - methodName: LockAsync - registerPlugin: - - type: AsyncGenerator.Core.Plugins.EmptyRegionRemover - assemblyName: AsyncGenerator.Core -- filePath: Velocity\NHibernate.Caches.Velocity\NHibernate.Caches.Velocity.csproj - concurrentRun: true - applyChanges: true - analyzation: - methodConversion: - - conversion: Ignore - hasAttributeName: ObsoleteAttribute - callForwarding: true - cancellationTokens: - guards: true - methodParameter: - - anyInterfaceRule: PubliclyExposedType - parameter: Optional - - parameter: Optional - rule: PubliclyExposedType - - parameter: Required - scanMethodBody: true - scanForMissingAsyncMembers: - - all: true - transformation: - configureAwaitArgument: false - localFunctions: true - asyncLock: - type: NHibernate.Util.AsyncLock - methodName: LockAsync - registerPlugin: - - type: AsyncGenerator.Core.Plugins.EmptyRegionRemover - assemblyName: AsyncGenerator.Core - filePath: NHibernate.Caches.Common.Tests\NHibernate.Caches.Common.Tests.csproj targetFramework: net461 concurrentRun: true diff --git a/CoreDistributedCache/NHibernate.Caches.CoreDistributedCache.Tests/NHibernate.Caches.CoreDistributedCache.Tests.csproj b/CoreDistributedCache/NHibernate.Caches.CoreDistributedCache.Tests/NHibernate.Caches.CoreDistributedCache.Tests.csproj index fd88b603..142e9329 100644 --- a/CoreDistributedCache/NHibernate.Caches.CoreDistributedCache.Tests/NHibernate.Caches.CoreDistributedCache.Tests.csproj +++ b/CoreDistributedCache/NHibernate.Caches.CoreDistributedCache.Tests/NHibernate.Caches.CoreDistributedCache.Tests.csproj @@ -30,7 +30,4 @@ - - - diff --git a/CoreDistributedCache/NHibernate.Caches.CoreDistributedCache/Async/CoreDistributedCache.cs b/CoreDistributedCache/NHibernate.Caches.CoreDistributedCache/Async/CoreDistributedCache.cs index 5b0411cf..23fb3866 100644 --- a/CoreDistributedCache/NHibernate.Caches.CoreDistributedCache/Async/CoreDistributedCache.cs +++ b/CoreDistributedCache/NHibernate.Caches.CoreDistributedCache/Async/CoreDistributedCache.cs @@ -21,11 +21,11 @@ namespace NHibernate.Caches.CoreDistributedCache { using System.Threading.Tasks; using System.Threading; - public partial class CoreDistributedCache : ICache + public partial class CoreDistributedCache : CacheBase { /// - public async Task GetAsync(object key, CancellationToken cancellationToken) + public override async Task GetAsync(object key, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); if (key == null) @@ -49,7 +49,7 @@ public async Task GetAsync(object key, CancellationToken cancellationTok } /// - public Task PutAsync(object key, object value, CancellationToken cancellationToken) + public override Task PutAsync(object key, object value, CancellationToken cancellationToken) { if (key == null) { @@ -93,7 +93,7 @@ public Task PutAsync(object key, object value, CancellationToken cancellationTok } /// - public Task RemoveAsync(object key, CancellationToken cancellationToken) + public override Task RemoveAsync(object key, CancellationToken cancellationToken) { if (key == null) { @@ -117,7 +117,7 @@ public Task RemoveAsync(object key, CancellationToken cancellationToken) } /// - public Task ClearAsync(CancellationToken cancellationToken) + public override Task ClearAsync(CancellationToken cancellationToken) { if (cancellationToken.IsCancellationRequested) { @@ -135,7 +135,7 @@ public Task ClearAsync(CancellationToken cancellationToken) } /// - public Task LockAsync(object key, CancellationToken cancellationToken) + public override Task LockAsync(object key, CancellationToken cancellationToken) { if (cancellationToken.IsCancellationRequested) { @@ -143,8 +143,7 @@ public Task LockAsync(object key, CancellationToken cancellationToken) } try { - Lock(key); - return Task.CompletedTask; + return Task.FromResult(Lock(key)); } catch (Exception ex) { @@ -153,7 +152,7 @@ public Task LockAsync(object key, CancellationToken cancellationToken) } /// - public Task UnlockAsync(object key, CancellationToken cancellationToken) + public override Task UnlockAsync(object key, object lockValue, CancellationToken cancellationToken) { if (cancellationToken.IsCancellationRequested) { @@ -161,7 +160,7 @@ public Task UnlockAsync(object key, CancellationToken cancellationToken) } try { - Unlock(key); + Unlock(key, lockValue); return Task.CompletedTask; } catch (Exception ex) diff --git a/CoreDistributedCache/NHibernate.Caches.CoreDistributedCache/CoreDistributedCache.cs b/CoreDistributedCache/NHibernate.Caches.CoreDistributedCache/CoreDistributedCache.cs index 7b78f30b..2019a10a 100644 --- a/CoreDistributedCache/NHibernate.Caches.CoreDistributedCache/CoreDistributedCache.cs +++ b/CoreDistributedCache/NHibernate.Caches.CoreDistributedCache/CoreDistributedCache.cs @@ -34,7 +34,7 @@ namespace NHibernate.Caches.CoreDistributedCache /// /// Pluggable cache implementation using implementations. /// - public partial class CoreDistributedCache : ICache + public partial class CoreDistributedCache : CacheBase { private static readonly INHibernateLogger Log = NHibernateLogger.For(typeof(CoreDistributedCache)); @@ -83,7 +83,7 @@ public CoreDistributedCache( } /// - public string RegionName { get; } + public override string RegionName { get; } /// /// The expiration delay applied to cached items. @@ -239,7 +239,7 @@ private string GetCacheKey(object key) } /// - public object Get(object key) + public override object Get(object key) { if (key == null) { @@ -262,7 +262,7 @@ public object Get(object key) } /// - public void Put(object key, object value) + public override void Put(object key, object value) { if (key == null) { @@ -295,7 +295,7 @@ public void Put(object key, object value) } /// - public void Remove(object key) + public override void Remove(object key) { if (key == null) { @@ -308,7 +308,7 @@ public void Remove(object key) } /// - public void Clear() + public override void Clear() { // Like IMemoryCache, it does not support Clear. Unlike it, it does neither provides a dependency // mechanism which would allow to implement it. @@ -316,29 +316,30 @@ public void Clear() } /// - public void Destroy() + public override void Destroy() { } /// - public void Lock(object key) + public override object Lock(object key) { // Do nothing + return null; } /// - public void Unlock(object key) + public override void Unlock(object key, object lockValue) { // Do nothing } /// - public long NextTimestamp() + public override long NextTimestamp() { return Timestamper.Next(); } /// - public int Timeout => Timestamper.OneMs * 60000; + public override int Timeout => Timestamper.OneMs * 60000; } } diff --git a/CoreDistributedCache/NHibernate.Caches.CoreDistributedCache/CoreDistributedCacheProvider.cs b/CoreDistributedCache/NHibernate.Caches.CoreDistributedCache/CoreDistributedCacheProvider.cs index f6a7c8cb..c5097187 100644 --- a/CoreDistributedCache/NHibernate.Caches.CoreDistributedCache/CoreDistributedCacheProvider.cs +++ b/CoreDistributedCache/NHibernate.Caches.CoreDistributedCache/CoreDistributedCacheProvider.cs @@ -88,7 +88,7 @@ static CoreDistributedCacheProvider() CacheFactory = (IDistributedCacheFactory) (ctorWithProperties != null ? ctorWithProperties.Invoke(new object[] { config.Properties }): - Cfg.Environment.BytecodeProvider.ObjectsFactory.CreateInstance(factoryClass)); + Cfg.Environment.ObjectsFactory.CreateInstance(factoryClass)); } catch (Exception e) { @@ -111,7 +111,9 @@ static CoreDistributedCacheProvider() #region ICacheProvider Members /// +#pragma warning disable 618 public ICache BuildCache(string regionName, IDictionary properties) +#pragma warning restore 618 { if (CacheFactory == null) throw new InvalidOperationException( diff --git a/CoreDistributedCache/NHibernate.Caches.CoreDistributedCache/NHibernate.Caches.CoreDistributedCache.csproj b/CoreDistributedCache/NHibernate.Caches.CoreDistributedCache/NHibernate.Caches.CoreDistributedCache.csproj index bd2a10e5..d0360c91 100644 --- a/CoreDistributedCache/NHibernate.Caches.CoreDistributedCache/NHibernate.Caches.CoreDistributedCache.csproj +++ b/CoreDistributedCache/NHibernate.Caches.CoreDistributedCache/NHibernate.Caches.CoreDistributedCache.csproj @@ -25,7 +25,7 @@ This provider is not bound to a specific implementation and require a cache fact - + diff --git a/CoreMemoryCache/NHibernate.Caches.CoreMemoryCache/Async/CoreMemoryCache.cs b/CoreMemoryCache/NHibernate.Caches.CoreMemoryCache/Async/CoreMemoryCache.cs deleted file mode 100644 index 236245f1..00000000 --- a/CoreMemoryCache/NHibernate.Caches.CoreMemoryCache/Async/CoreMemoryCache.cs +++ /dev/null @@ -1,145 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -using System; -using NHibernate.Cache; -using System.Collections.Generic; -using System.Threading; -using Microsoft.Extensions.Caching.Memory; -using Microsoft.Extensions.Primitives; -using NHibernate.Util; - -namespace NHibernate.Caches.CoreMemoryCache -{ - using System.Threading.Tasks; - public partial class CoreMemoryCache : ICache - { - - /// - public Task GetAsync(object key, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(Get(key)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// - public Task PutAsync(object key, object value, CancellationToken cancellationToken) - { - if (key == null) - { - throw new ArgumentNullException(nameof(key), "null key not allowed"); - } - - if (value == null) - { - throw new ArgumentNullException(nameof(value), "null value not allowed"); - } - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - Put(key, value); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// - public Task RemoveAsync(object key, CancellationToken cancellationToken) - { - if (key == null) - { - throw new ArgumentNullException(nameof(key)); - } - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - Remove(key); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// - public Task ClearAsync(CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - Clear(); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// - public Task LockAsync(object key, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - Lock(key); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// - public Task UnlockAsync(object key, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - Unlock(key); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - } -} diff --git a/CoreMemoryCache/NHibernate.Caches.CoreMemoryCache/CoreMemoryCache.cs b/CoreMemoryCache/NHibernate.Caches.CoreMemoryCache/CoreMemoryCache.cs index ed3fb152..06312ef8 100644 --- a/CoreMemoryCache/NHibernate.Caches.CoreMemoryCache/CoreMemoryCache.cs +++ b/CoreMemoryCache/NHibernate.Caches.CoreMemoryCache/CoreMemoryCache.cs @@ -36,10 +36,10 @@ namespace NHibernate.Caches.CoreMemoryCache /// /// Priority is not configurable because it is un-usable: the compaction on memory pressure feature has been /// removed from MemoryCache, only explicit compaction or size limit compaction may use priorities. But - /// API does not have a suitable method for triggering compaction, and size of each - /// cached entry has to be user provided, which API does not support. + /// API does not have a suitable method for triggering compaction, and size of each + /// cached entry has to be user provided, which API does not support. /// - public partial class CoreMemoryCache : ICache + public class CoreMemoryCache : CacheBase { private static readonly INHibernateLogger Log = NHibernateLogger.For(typeof(CoreMemoryCache)); @@ -108,7 +108,7 @@ public CoreMemoryCache(string region, IDictionary properties) } /// - public string RegionName { get; } + public override string RegionName { get; } /// /// The expiration delay applied to cached items. @@ -197,7 +197,7 @@ private object GetCacheKey(object key) } /// - public object Get(object key) + public override object Get(object key) { if (key == null) { @@ -211,7 +211,7 @@ public object Get(object key) } /// - public void Put(object key, object value) + public override void Put(object key, object value) { if (key == null) { @@ -244,7 +244,7 @@ public void Put(object key, object value) } /// - public void Remove(object key) + public override void Remove(object key) { if (key == null) { @@ -257,7 +257,7 @@ public void Remove(object key) } /// - public void Clear() + public override void Clear() { _clearTokenLock.EnterWriteLock(); try @@ -273,7 +273,7 @@ public void Clear() } /// - public void Destroy() + public override void Destroy() { Clear(); _clearTokenLock.Dispose(); @@ -281,24 +281,25 @@ public void Destroy() } /// - public void Lock(object key) + public override object Lock(object key) { // Do nothing + return null; } /// - public void Unlock(object key) + public override void Unlock(object key, object lockValue) { // Do nothing } /// - public long NextTimestamp() + public override long NextTimestamp() { return Timestamper.Next(); } /// - public int Timeout => Timestamper.OneMs * 60000; + public override int Timeout => Timestamper.OneMs * 60000; } } diff --git a/CoreMemoryCache/NHibernate.Caches.CoreMemoryCache/CoreMemoryCacheProvider.cs b/CoreMemoryCache/NHibernate.Caches.CoreMemoryCache/CoreMemoryCacheProvider.cs index 99fa6ec6..e1605bb1 100644 --- a/CoreMemoryCache/NHibernate.Caches.CoreMemoryCache/CoreMemoryCacheProvider.cs +++ b/CoreMemoryCache/NHibernate.Caches.CoreMemoryCache/CoreMemoryCacheProvider.cs @@ -85,7 +85,9 @@ static CoreMemoryCacheProvider() #region ICacheProvider Members /// +#pragma warning disable 618 public ICache BuildCache(string regionName, IDictionary properties) +#pragma warning restore 618 { if (regionName == null) { diff --git a/CoreMemoryCache/NHibernate.Caches.CoreMemoryCache/NHibernate.Caches.CoreMemoryCache.csproj b/CoreMemoryCache/NHibernate.Caches.CoreMemoryCache/NHibernate.Caches.CoreMemoryCache.csproj index 3e003fab..aebb830d 100644 --- a/CoreMemoryCache/NHibernate.Caches.CoreMemoryCache/NHibernate.Caches.CoreMemoryCache.csproj +++ b/CoreMemoryCache/NHibernate.Caches.CoreMemoryCache/NHibernate.Caches.CoreMemoryCache.csproj @@ -22,7 +22,7 @@ - + diff --git a/EnyimMemcached/NHibernate.Caches.EnyimMemcached/Async/MemCacheClient.cs b/EnyimMemcached/NHibernate.Caches.EnyimMemcached/Async/MemCacheClient.cs deleted file mode 100644 index 50d74576..00000000 --- a/EnyimMemcached/NHibernate.Caches.EnyimMemcached/Async/MemCacheClient.cs +++ /dev/null @@ -1,150 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -using System; -using System.Collections; -using System.Collections.Generic; -using Enyim.Caching; -using Enyim.Caching.Memcached; -using NHibernate.Cache; -using NHibernate.Caches.Util; -using Environment = NHibernate.Cfg.Environment; - -namespace NHibernate.Caches.EnyimMemcached -{ - using System.Threading.Tasks; - using System.Threading; - public partial class MemCacheClient : ICache - { - - #region ICache Members - - /// - public Task GetAsync(object key, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(Get(key)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// - public Task PutAsync(object key, object value, CancellationToken cancellationToken) - { - if (key == null) - { - throw new ArgumentNullException("key", "null key not allowed"); - } - if (value == null) - { - throw new ArgumentNullException("value", "null value not allowed"); - } - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - Put(key, value); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// - public Task RemoveAsync(object key, CancellationToken cancellationToken) - { - if (key == null) - { - throw new ArgumentNullException("key"); - } - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - Remove(key); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// - public Task ClearAsync(CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - Clear(); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// - public Task LockAsync(object key, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - Lock(key); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// - public Task UnlockAsync(object key, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - Unlock(key); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - #endregion - } -} diff --git a/EnyimMemcached/NHibernate.Caches.EnyimMemcached/MemCacheClient.cs b/EnyimMemcached/NHibernate.Caches.EnyimMemcached/MemCacheClient.cs index 55e2761f..afec585c 100644 --- a/EnyimMemcached/NHibernate.Caches.EnyimMemcached/MemCacheClient.cs +++ b/EnyimMemcached/NHibernate.Caches.EnyimMemcached/MemCacheClient.cs @@ -12,7 +12,7 @@ namespace NHibernate.Caches.EnyimMemcached /// /// Pluggable cache implementation using Memcached and the EnyimMemcached client library. /// - public partial class MemCacheClient : ICache + public class MemCacheClient : CacheBase { private static readonly INHibernateLogger log; @@ -92,10 +92,10 @@ public MemCacheClient(string regionName, IDictionary properties, } } - #region ICache Members + #region CacheBase Members /// - public object Get(object key) + public override object Get(object key) { if (key == null) { @@ -119,7 +119,7 @@ public object Get(object key) } /// - public void Put(object key, object value) + public override void Put(object key, object value) { if (key == null) { @@ -142,7 +142,7 @@ public void Put(object key, object value) } /// - public void Remove(object key) + public override void Remove(object key) { if (key == null) { @@ -153,43 +153,44 @@ public void Remove(object key) } /// - public void Clear() + public override void Clear() { client.FlushAll(); } /// - public void Destroy() + public override void Destroy() { Clear(); } /// - public void Lock(object key) + public override object Lock(object key) { // do nothing + return null; } /// - public void Unlock(object key) + public override void Unlock(object key, object lockValue) { // do nothing } /// - public long NextTimestamp() + public override long NextTimestamp() { return Timestamper.Next(); } /// - public int Timeout + public override int Timeout { get { return Timestamper.OneMs*60000; } } /// - public string RegionName + public override string RegionName { get { return region; } } diff --git a/EnyimMemcached/NHibernate.Caches.EnyimMemcached/MemCacheProvider.cs b/EnyimMemcached/NHibernate.Caches.EnyimMemcached/MemCacheProvider.cs index 60f4b469..d77cb791 100644 --- a/EnyimMemcached/NHibernate.Caches.EnyimMemcached/MemCacheProvider.cs +++ b/EnyimMemcached/NHibernate.Caches.EnyimMemcached/MemCacheProvider.cs @@ -35,7 +35,9 @@ static MemCacheProvider() #region ICacheProvider Members /// +#pragma warning disable 618 public ICache BuildCache(string regionName, IDictionary properties) +#pragma warning restore 618 { if (regionName == null) { diff --git a/EnyimMemcached/NHibernate.Caches.EnyimMemcached/NHibernate.Caches.EnyimMemcached.csproj b/EnyimMemcached/NHibernate.Caches.EnyimMemcached/NHibernate.Caches.EnyimMemcached.csproj index 7a6a4065..2864ae37 100644 --- a/EnyimMemcached/NHibernate.Caches.EnyimMemcached/NHibernate.Caches.EnyimMemcached.csproj +++ b/EnyimMemcached/NHibernate.Caches.EnyimMemcached/NHibernate.Caches.EnyimMemcached.csproj @@ -20,7 +20,7 @@ - + diff --git a/MemCache/NHibernate.Caches.MemCache/Async/MemCacheClient.cs b/MemCache/NHibernate.Caches.MemCache/Async/MemCacheClient.cs deleted file mode 100644 index 631bf4c2..00000000 --- a/MemCache/NHibernate.Caches.MemCache/Async/MemCacheClient.cs +++ /dev/null @@ -1,148 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -using System; -using System.Collections; -using System.Collections.Generic; -using Memcached.ClientLibrary; -using NHibernate.Cache; -using NHibernate.Caches.Util; - -namespace NHibernate.Caches.MemCache -{ - using System.Threading.Tasks; - using System.Threading; - public partial class MemCacheClient : ICache - { - - #region ICache Members - - /// - public Task GetAsync(object key, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(Get(key)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// - public Task PutAsync(object key, object value, CancellationToken cancellationToken) - { - if (key == null) - { - throw new ArgumentNullException("key", "null key not allowed"); - } - if (value == null) - { - throw new ArgumentNullException("value", "null value not allowed"); - } - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - Put(key, value); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// - public Task RemoveAsync(object key, CancellationToken cancellationToken) - { - if (key == null) - { - throw new ArgumentNullException("key"); - } - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - Remove(key); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// - public Task ClearAsync(CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - Clear(); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// - public Task LockAsync(object key, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - Lock(key); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// - public Task UnlockAsync(object key, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - Unlock(key); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - #endregion - } -} diff --git a/MemCache/NHibernate.Caches.MemCache/MemCacheClient.cs b/MemCache/NHibernate.Caches.MemCache/MemCacheClient.cs index 491828d7..db631106 100644 --- a/MemCache/NHibernate.Caches.MemCache/MemCacheClient.cs +++ b/MemCache/NHibernate.Caches.MemCache/MemCacheClient.cs @@ -36,7 +36,7 @@ namespace NHibernate.Caches.MemCache /// /// Pluggable cache implementation using Memcached. /// - public partial class MemCacheClient : ICache + public class MemCacheClient : CacheBase { internal const string PoolName = "nhibernate"; private static readonly INHibernateLogger log; @@ -125,10 +125,10 @@ private static string GetExpirationString(IDictionary props) return result; } - #region ICache Members + #region CacheBase Members /// - public object Get(object key) + public override object Get(object key) { if (key == null) { @@ -155,7 +155,7 @@ public object Get(object key) } /// - public void Put(object key, object value) + public override void Put(object key, object value) { if (key == null) { @@ -176,7 +176,7 @@ public void Put(object key, object value) } /// - public void Remove(object key) + public override void Remove(object key) { if (key == null) { @@ -191,43 +191,44 @@ public void Remove(object key) } /// - public void Clear() + public override void Clear() { client.FlushAll(); } /// - public void Destroy() + public override void Destroy() { Clear(); } /// - public void Lock(object key) + public override object Lock(object key) { // do nothing + return null; } /// - public void Unlock(object key) + public override void Unlock(object key, object lockValue) { // do nothing } /// - public long NextTimestamp() + public override long NextTimestamp() { return Timestamper.Next(); } /// - public int Timeout + public override int Timeout { get { return Timestamper.OneMs * 60000; } } /// - public string RegionName + public override string RegionName { get { return region; } } diff --git a/MemCache/NHibernate.Caches.MemCache/MemCacheProvider.cs b/MemCache/NHibernate.Caches.MemCache/MemCacheProvider.cs index 4be400e7..dfcae5b1 100644 --- a/MemCache/NHibernate.Caches.MemCache/MemCacheProvider.cs +++ b/MemCache/NHibernate.Caches.MemCache/MemCacheProvider.cs @@ -72,7 +72,9 @@ static MemCacheProvider() #region ICacheProvider Members /// +#pragma warning disable 618 public ICache BuildCache(string regionName, IDictionary properties) +#pragma warning restore 618 { if (regionName == null) { diff --git a/MemCache/NHibernate.Caches.MemCache/NHibernate.Caches.MemCache.csproj b/MemCache/NHibernate.Caches.MemCache/NHibernate.Caches.MemCache.csproj index 54d99c24..48efa656 100644 --- a/MemCache/NHibernate.Caches.MemCache/NHibernate.Caches.MemCache.csproj +++ b/MemCache/NHibernate.Caches.MemCache/NHibernate.Caches.MemCache.csproj @@ -20,7 +20,7 @@ - + diff --git a/NHibernate.Caches.Common.Tests/CacheFixture.cs b/NHibernate.Caches.Common.Tests/CacheFixture.cs index 420da792..577cedd4 100644 --- a/NHibernate.Caches.Common.Tests/CacheFixture.cs +++ b/NHibernate.Caches.Common.Tests/CacheFixture.cs @@ -319,10 +319,10 @@ protected IDictionary GetPropertiesForExpiration(string expirati return props; } - protected ICache GetCacheForExpiration(string cacheRegion, string expirationSetting, int expirySeconds) + protected CacheBase GetCacheForExpiration(string cacheRegion, string expirationSetting, int expirySeconds) { var props = GetPropertiesForExpiration(expirationSetting, expirySeconds.ToString()); - var cache = DefaultProvider.BuildCache(cacheRegion, props); + var cache = (CacheBase) DefaultProvider.BuildCache(cacheRegion, props); return cache; } } diff --git a/NHibernate.Caches.Common.Tests/Fixture.cs b/NHibernate.Caches.Common.Tests/Fixture.cs index 0ce8777d..67279620 100644 --- a/NHibernate.Caches.Common.Tests/Fixture.cs +++ b/NHibernate.Caches.Common.Tests/Fixture.cs @@ -62,9 +62,9 @@ protected ICacheProvider GetNewProvider() return provider; } - protected ICache GetDefaultCache() + protected CacheBase GetDefaultCache() { - var cache = DefaultProvider.BuildCache(DefaultRegion, GetDefaultProperties()); + var cache = (CacheBase) DefaultProvider.BuildCache(DefaultRegion, GetDefaultProperties()); Assert.That(cache, Is.Not.Null, "No default cache returned"); return cache; } diff --git a/NHibernate.Caches.Common.Tests/NHibernate.Caches.Common.Tests.csproj b/NHibernate.Caches.Common.Tests/NHibernate.Caches.Common.Tests.csproj index 7191879f..b8537f32 100644 --- a/NHibernate.Caches.Common.Tests/NHibernate.Caches.Common.Tests.csproj +++ b/NHibernate.Caches.Common.Tests/NHibernate.Caches.Common.Tests.csproj @@ -13,6 +13,6 @@ - + diff --git a/Prevalence/NHibernate.Caches.Prevalence/Async/PrevalenceCache.cs b/Prevalence/NHibernate.Caches.Prevalence/Async/PrevalenceCache.cs deleted file mode 100644 index abed7b6b..00000000 --- a/Prevalence/NHibernate.Caches.Prevalence/Async/PrevalenceCache.cs +++ /dev/null @@ -1,133 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -using System; -using System.Collections; -using NHibernate.Cache; - -namespace NHibernate.Caches.Prevalence -{ - using System.Threading.Tasks; - using System.Threading; - public partial class PrevalenceCache : ICache - { - - #region ICache Members - - /// - public Task GetAsync(object key, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(Get(key)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// - public Task PutAsync(object key, object value, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - Put(key, value); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// - public Task RemoveAsync(object key, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - Remove(key); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// - public Task ClearAsync(CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - Clear(); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// - public Task LockAsync(object key, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - Lock(key); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// - public Task UnlockAsync(object key, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - Unlock(key); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - #endregion - } -} diff --git a/Prevalence/NHibernate.Caches.Prevalence/NHibernate.Caches.Prevalence.csproj b/Prevalence/NHibernate.Caches.Prevalence/NHibernate.Caches.Prevalence.csproj index d0ff9cca..becfb7aa 100644 --- a/Prevalence/NHibernate.Caches.Prevalence/NHibernate.Caches.Prevalence.csproj +++ b/Prevalence/NHibernate.Caches.Prevalence/NHibernate.Caches.Prevalence.csproj @@ -16,7 +16,7 @@ - + diff --git a/Prevalence/NHibernate.Caches.Prevalence/PrevalenceCache.cs b/Prevalence/NHibernate.Caches.Prevalence/PrevalenceCache.cs index 482a2985..90717e7e 100644 --- a/Prevalence/NHibernate.Caches.Prevalence/PrevalenceCache.cs +++ b/Prevalence/NHibernate.Caches.Prevalence/PrevalenceCache.cs @@ -7,7 +7,7 @@ namespace NHibernate.Caches.Prevalence /// /// Pluggable cache implementation using Bamboo Prevalence. /// - public partial class PrevalenceCache : ICache + public class PrevalenceCache : CacheBase { private const string CacheKeyPrefix = "NHibernate-Cache:"; private static readonly INHibernateLogger log = NHibernateLogger.For(typeof(PrevalenceCache)); @@ -36,10 +36,10 @@ public PrevalenceCache(string region, CacheSystem system) this.system = system ?? new CacheSystem(); } - #region ICache Members + #region CacheBase Members /// - public object Get(object key) + public override object Get(object key) { if (key == null) { @@ -67,7 +67,7 @@ public object Get(object key) } /// - public void Put(object key, object value) + public override void Put(object key, object value) { if (key == null) { @@ -85,7 +85,7 @@ public void Put(object key, object value) } /// - public void Remove(object key) + public override void Remove(object key) { if (key == null) { @@ -98,45 +98,46 @@ public void Remove(object key) } /// - public void Clear() + public override void Clear() { log.Info("clearing all objects from system"); system.Clear(); } /// - public void Destroy() + public override void Destroy() { log.Info("'Destroy' was called"); Clear(); } /// - public void Lock(object key) + public override object Lock(object key) { // Do nothing + return null; } /// - public void Unlock(object key) + public override void Unlock(object key, object lockValue) { // Do nothing } /// - public long NextTimestamp() + public override long NextTimestamp() { return Timestamper.Next(); } /// - public int Timeout + public override int Timeout { get { return Timestamper.OneMs * 60000; } // 60 seconds } /// - public string RegionName + public override string RegionName { get { return region; } } diff --git a/Prevalence/NHibernate.Caches.Prevalence/PrevalenceCacheProvider.cs b/Prevalence/NHibernate.Caches.Prevalence/PrevalenceCacheProvider.cs index e0f22edc..c640c803 100644 --- a/Prevalence/NHibernate.Caches.Prevalence/PrevalenceCacheProvider.cs +++ b/Prevalence/NHibernate.Caches.Prevalence/PrevalenceCacheProvider.cs @@ -27,7 +27,9 @@ public class PrevalenceCacheProvider : ICacheProvider /// the directory on the file system where the Prevalence engine will save data. /// It can be relative to the current directory or a full path. If the directory /// doesn't exist, it will be created. +#pragma warning disable 618 public ICache BuildCache(string regionName, IDictionary properties) +#pragma warning restore 618 { if (regionName == null) { diff --git a/RtMemoryCache/NHibernate.Caches.RtMemoryCache.Tests/RtMemoryCacheProviderFixture.cs b/RtMemoryCache/NHibernate.Caches.RtMemoryCache.Tests/RtMemoryCacheProviderFixture.cs index e8f4a448..3bb4d69a 100644 --- a/RtMemoryCache/NHibernate.Caches.RtMemoryCache.Tests/RtMemoryCacheProviderFixture.cs +++ b/RtMemoryCache/NHibernate.Caches.RtMemoryCache.Tests/RtMemoryCacheProviderFixture.cs @@ -40,7 +40,7 @@ public class RtMemoryCacheProviderFixture : CacheProviderFixture [Test] public void TestBuildCacheFromConfig() { - ICache cache = DefaultProvider.BuildCache("foo", null); + var cache = DefaultProvider.BuildCache("foo", null); Assert.That(cache, Is.Not.Null, "pre-configured cache not found"); } diff --git a/RtMemoryCache/NHibernate.Caches.RtMemoryCache/Async/RtMemoryCache.cs b/RtMemoryCache/NHibernate.Caches.RtMemoryCache/Async/RtMemoryCache.cs deleted file mode 100644 index 054c479d..00000000 --- a/RtMemoryCache/NHibernate.Caches.RtMemoryCache/Async/RtMemoryCache.cs +++ /dev/null @@ -1,144 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -using System; -using System.Collections; -using System.Runtime.Caching; -using NHibernate.Cache; -using System.Collections.Generic; -using NHibernate.Util; - -namespace NHibernate.Caches.RtMemoryCache -{ - using System.Threading.Tasks; - using System.Threading; - public partial class RtMemoryCache : ICache - { - - /// - public Task GetAsync(object key, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(Get(key)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// - public Task PutAsync(object key, object value, CancellationToken cancellationToken) - { - if (key == null) - { - throw new ArgumentNullException(nameof(key), "null key not allowed"); - } - if (value == null) - { - throw new ArgumentNullException(nameof(value), "null value not allowed"); - } - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - Put(key, value); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// - public Task RemoveAsync(object key, CancellationToken cancellationToken) - { - if (key == null) - { - throw new ArgumentNullException(nameof(key)); - } - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - Remove(key); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// - public Task ClearAsync(CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - Clear(); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// - public Task LockAsync(object key, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - Lock(key); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// - public Task UnlockAsync(object key, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - Unlock(key); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - } -} diff --git a/RtMemoryCache/NHibernate.Caches.RtMemoryCache/NHibernate.Caches.RtMemoryCache.csproj b/RtMemoryCache/NHibernate.Caches.RtMemoryCache/NHibernate.Caches.RtMemoryCache.csproj index 6dbb8241..077ded5b 100644 --- a/RtMemoryCache/NHibernate.Caches.RtMemoryCache/NHibernate.Caches.RtMemoryCache.csproj +++ b/RtMemoryCache/NHibernate.Caches.RtMemoryCache/NHibernate.Caches.RtMemoryCache.csproj @@ -22,7 +22,7 @@ - + diff --git a/RtMemoryCache/NHibernate.Caches.RtMemoryCache/RtMemoryCache.cs b/RtMemoryCache/NHibernate.Caches.RtMemoryCache/RtMemoryCache.cs index a4162737..1413a704 100644 --- a/RtMemoryCache/NHibernate.Caches.RtMemoryCache/RtMemoryCache.cs +++ b/RtMemoryCache/NHibernate.Caches.RtMemoryCache/RtMemoryCache.cs @@ -32,7 +32,7 @@ namespace NHibernate.Caches.RtMemoryCache /// /// Pluggable cache implementation using the System.Runtime.Caching classes. /// - public partial class RtMemoryCache : ICache + public class RtMemoryCache : CacheBase { private static readonly INHibernateLogger Log = NHibernateLogger.For(typeof(RtMemoryCache)); private string _regionPrefix; @@ -183,7 +183,7 @@ private string GetCacheKey(object key) } /// - public object Get(object key) + public override object Get(object key) { if (key == null) { @@ -203,7 +203,7 @@ public object Get(object key) } /// - public void Put(object key, object value) + public override void Put(object key, object value) { if (key == null) { @@ -237,7 +237,7 @@ public void Put(object key, object value) } /// - public void Remove(object key) + public override void Remove(object key) { if (key == null) { @@ -249,7 +249,7 @@ public void Remove(object key) } /// - public void Clear() + public override void Clear() { RemoveRootCacheKey(); StoreRootCacheKey(); @@ -289,33 +289,34 @@ private void RemoveRootCacheKey() } /// - public void Destroy() + public override void Destroy() { Clear(); } /// - public void Lock(object key) + public override object Lock(object key) { // Do nothing + return null; } /// - public void Unlock(object key) + public override void Unlock(object key, object lockValue) { // Do nothing } /// - public long NextTimestamp() + public override long NextTimestamp() { return Timestamper.Next(); } /// - public int Timeout => Timestamper.OneMs * 60000; + public override int Timeout => Timestamper.OneMs * 60000; /// - public string RegionName => Region; + public override string RegionName => Region; } } diff --git a/RtMemoryCache/NHibernate.Caches.RtMemoryCache/RtMemoryCacheProvider.cs b/RtMemoryCache/NHibernate.Caches.RtMemoryCache/RtMemoryCacheProvider.cs index 0199f7bc..18f728bc 100644 --- a/RtMemoryCache/NHibernate.Caches.RtMemoryCache/RtMemoryCacheProvider.cs +++ b/RtMemoryCache/NHibernate.Caches.RtMemoryCache/RtMemoryCacheProvider.cs @@ -51,7 +51,9 @@ static RtMemoryCacheProvider() #region ICacheProvider Members /// +#pragma warning disable 618 public ICache BuildCache(string regionName, IDictionary properties) +#pragma warning restore 618 { if (regionName == null) { diff --git a/SharedCache/NHibernate.Caches.SharedCache/Async/SharedCacheClient.cs b/SharedCache/NHibernate.Caches.SharedCache/Async/SharedCacheClient.cs deleted file mode 100644 index 5c709281..00000000 --- a/SharedCache/NHibernate.Caches.SharedCache/Async/SharedCacheClient.cs +++ /dev/null @@ -1,142 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -using System; -using System.Collections.Generic; -using MergeSystem.Indexus.WinServiceCommon.Provider.Cache; -using NHibernate.Cache; - -namespace NHibernate.Caches.SharedCache -{ - using System.Threading.Tasks; - using System.Threading; - public partial class SharedCacheClient : ICache - { - - /// - public Task GetAsync(object key, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(Get(key)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// - public Task PutAsync(object key, object value, CancellationToken cancellationToken) - { - if (key == null) - { - throw new ArgumentNullException("key", "null key not allowed"); - } - if (value == null) - { - throw new ArgumentNullException("value", "null value not allowed"); - } - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - Put(key, value); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// - public Task RemoveAsync(object key, CancellationToken cancellationToken) - { - if (key == null) - { - throw new ArgumentNullException("key"); - } - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - Remove(key); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// - public Task ClearAsync(CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - Clear(); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// - public Task LockAsync(object key, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - Lock(key); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// - public Task UnlockAsync(object key, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - Unlock(key); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - } -} diff --git a/SharedCache/NHibernate.Caches.SharedCache/NHibernate.Caches.SharedCache.csproj b/SharedCache/NHibernate.Caches.SharedCache/NHibernate.Caches.SharedCache.csproj index 9408754e..fee776a7 100644 --- a/SharedCache/NHibernate.Caches.SharedCache/NHibernate.Caches.SharedCache.csproj +++ b/SharedCache/NHibernate.Caches.SharedCache/NHibernate.Caches.SharedCache.csproj @@ -10,7 +10,7 @@ false - + diff --git a/SharedCache/NHibernate.Caches.SharedCache/SharedCacheClient.cs b/SharedCache/NHibernate.Caches.SharedCache/SharedCacheClient.cs index e29a4397..904eaa97 100644 --- a/SharedCache/NHibernate.Caches.SharedCache/SharedCacheClient.cs +++ b/SharedCache/NHibernate.Caches.SharedCache/SharedCacheClient.cs @@ -33,7 +33,7 @@ namespace NHibernate.Caches.SharedCache /// /// Pluggable cache implementation using indeXus.Net Shared Cache. /// - public partial class SharedCacheClient : ICache + public class SharedCacheClient : CacheBase { private static readonly INHibernateLogger log; private readonly string region; @@ -67,7 +67,7 @@ public SharedCacheClient(string regionName, IDictionary properti } /// - public object Get(object key) + public override object Get(object key) { if (key == null) { @@ -79,7 +79,7 @@ public object Get(object key) } /// - public void Put(object key, object value) + public override void Put(object key, object value) { if (key == null) { @@ -96,7 +96,7 @@ public void Put(object key, object value) } /// - public void Remove(object key) + public override void Remove(object key) { if (key == null) { @@ -108,37 +108,37 @@ public void Remove(object key) } /// - public void Clear() + public override void Clear() { IndexusDistributionCache.SharedCache.Clear(); } /// - public void Destroy() + public override void Destroy() { Clear(); } /// - public void Lock(object key) {} + public override object Lock(object key) => null; /// - public void Unlock(object key) {} + public override void Unlock(object key, object lockValue) {} /// - public long NextTimestamp() + public override long NextTimestamp() { return Timestamper.Next(); } /// - public int Timeout + public override int Timeout { get { return Timestamper.OneMs * 60000; } // 60 seconds } /// - public string RegionName + public override string RegionName { get { return region; } } diff --git a/SharedCache/NHibernate.Caches.SharedCache/SharedCacheProvider.cs b/SharedCache/NHibernate.Caches.SharedCache/SharedCacheProvider.cs index 3f5663ba..a5901a99 100644 --- a/SharedCache/NHibernate.Caches.SharedCache/SharedCacheProvider.cs +++ b/SharedCache/NHibernate.Caches.SharedCache/SharedCacheProvider.cs @@ -45,7 +45,9 @@ static SharedCacheProvider() } /// +#pragma warning disable 618 public ICache BuildCache(string regionName, IDictionary properties) +#pragma warning restore 618 { if (regionName == null) { diff --git a/SysCache/NHibernate.Caches.SysCache/Async/SysCache.cs b/SysCache/NHibernate.Caches.SysCache/Async/SysCache.cs deleted file mode 100644 index 068c5ea1..00000000 --- a/SysCache/NHibernate.Caches.SysCache/Async/SysCache.cs +++ /dev/null @@ -1,145 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -using System; -using System.Collections; -using System.Web; -using System.Web.Caching; -using NHibernate.Cache; -using System.Collections.Generic; -using NHibernate.Util; - -namespace NHibernate.Caches.SysCache -{ - using System.Threading.Tasks; - using System.Threading; - public partial class SysCache : ICache - { - - /// - public Task GetAsync(object key, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(Get(key)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// - public Task PutAsync(object key, object value, CancellationToken cancellationToken) - { - if (key == null) - { - throw new ArgumentNullException(nameof(key), "null key not allowed"); - } - if (value == null) - { - throw new ArgumentNullException(nameof(value), "null value not allowed"); - } - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - Put(key, value); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// - public Task RemoveAsync(object key, CancellationToken cancellationToken) - { - if (key == null) - { - throw new ArgumentNullException(nameof(key)); - } - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - Remove(key); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// - public Task ClearAsync(CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - Clear(); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// - public Task LockAsync(object key, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - Lock(key); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// - public Task UnlockAsync(object key, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - Unlock(key); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - } -} diff --git a/SysCache/NHibernate.Caches.SysCache/NHibernate.Caches.SysCache.csproj b/SysCache/NHibernate.Caches.SysCache/NHibernate.Caches.SysCache.csproj index 0c2a94d4..8ce1e5dd 100644 --- a/SysCache/NHibernate.Caches.SysCache/NHibernate.Caches.SysCache.csproj +++ b/SysCache/NHibernate.Caches.SysCache/NHibernate.Caches.SysCache.csproj @@ -19,7 +19,7 @@ - + diff --git a/SysCache/NHibernate.Caches.SysCache/SysCache.cs b/SysCache/NHibernate.Caches.SysCache/SysCache.cs index d9873599..9d630b25 100644 --- a/SysCache/NHibernate.Caches.SysCache/SysCache.cs +++ b/SysCache/NHibernate.Caches.SysCache/SysCache.cs @@ -33,7 +33,7 @@ namespace NHibernate.Caches.SysCache /// /// Pluggable cache implementation using the System.Web.Caching classes. /// - public partial class SysCache : ICache + public class SysCache : CacheBase { private static readonly INHibernateLogger Log = NHibernateLogger.For(typeof(SysCache)); private string _regionPrefix; @@ -242,7 +242,7 @@ private string GetCacheKey(object key) } /// - public object Get(object key) + public override object Get(object key) { if (key == null) { @@ -262,7 +262,7 @@ public object Get(object key) } /// - public void Put(object key, object value) + public override void Put(object key, object value) { if (key == null) { @@ -297,7 +297,7 @@ public void Put(object key, object value) } /// - public void Remove(object key) + public override void Remove(object key) { if (key == null) { @@ -309,7 +309,7 @@ public void Remove(object key) } /// - public void Clear() + public override void Clear() { RemoveRootCacheKey(); StoreRootCacheKey(); @@ -347,33 +347,34 @@ private void RemoveRootCacheKey() } /// - public void Destroy() + public override void Destroy() { Clear(); } /// - public void Lock(object key) + public override object Lock(object key) { // Do nothing + return null; } /// - public void Unlock(object key) + public override void Unlock(object key, object lockValue) { // Do nothing } /// - public long NextTimestamp() + public override long NextTimestamp() { return Timestamper.Next(); } /// - public int Timeout => Timestamper.OneMs * 60000; + public override int Timeout => Timestamper.OneMs * 60000; /// - public string RegionName => Region; + public override string RegionName => Region; } } diff --git a/SysCache/NHibernate.Caches.SysCache/SysCacheProvider.cs b/SysCache/NHibernate.Caches.SysCache/SysCacheProvider.cs index ff606b34..b0a98376 100644 --- a/SysCache/NHibernate.Caches.SysCache/SysCacheProvider.cs +++ b/SysCache/NHibernate.Caches.SysCache/SysCacheProvider.cs @@ -51,7 +51,9 @@ static SysCacheProvider() #region ICacheProvider Members /// +#pragma warning disable 618 public ICache BuildCache(string regionName, IDictionary properties) +#pragma warning restore 618 { if (regionName == null) { diff --git a/SysCache2/NHibernate.Caches.SysCache2.Tests/SysCacheProviderFixture.cs b/SysCache2/NHibernate.Caches.SysCache2.Tests/SysCacheProviderFixture.cs index c91aa584..b8cea81c 100644 --- a/SysCache2/NHibernate.Caches.SysCache2.Tests/SysCacheProviderFixture.cs +++ b/SysCache2/NHibernate.Caches.SysCache2.Tests/SysCacheProviderFixture.cs @@ -48,7 +48,7 @@ protected override void Configure(Dictionary defaultProperties) [Test] public void TestBuildCacheFromConfig() { - ICache cache = DefaultProvider.BuildCache("foo", null); + var cache = DefaultProvider.BuildCache("foo", null); Assert.That(cache, Is.Not.Null, "pre-configured cache not found"); } diff --git a/SysCache2/NHibernate.Caches.SysCache2/Async/SysCacheRegion.cs b/SysCache2/NHibernate.Caches.SysCache2/Async/SysCacheRegion.cs deleted file mode 100644 index 9e94bde8..00000000 --- a/SysCache2/NHibernate.Caches.SysCache2/Async/SysCacheRegion.cs +++ /dev/null @@ -1,154 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Web; -using System.Web.Caching; -using NHibernate.Cache; -using NHibernate.Util; -using Environment = NHibernate.Cfg.Environment; - -namespace NHibernate.Caches.SysCache2 -{ - using System.Threading.Tasks; - using System.Threading; - public partial class SysCacheRegion : ICache - { - - #region ICache Members - - /// - public Task ClearAsync(CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - Clear(); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// - public Task GetAsync(object key, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(Get(key)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// - public Task LockAsync(object key, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - Lock(key); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// - [SuppressMessage("Microsoft.Reliability", "CA2000:DisposeObjectsBeforeLosingScope")] - public Task PutAsync(object key, object value, CancellationToken cancellationToken) - { - //validate the params - if (key == null) - { - throw new ArgumentNullException(nameof(key)); - } - - if (value == null) - { - throw new ArgumentNullException(nameof(value)); - } - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - Put(key, value); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// - public Task RemoveAsync(object key, CancellationToken cancellationToken) - { - if (key == null) - { - throw new ArgumentNullException(nameof(key)); - } - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - Remove(key); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// - public Task UnlockAsync(object key, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - Unlock(key); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - #endregion - } -} diff --git a/SysCache2/NHibernate.Caches.SysCache2/NHibernate.Caches.SysCache2.csproj b/SysCache2/NHibernate.Caches.SysCache2/NHibernate.Caches.SysCache2.csproj index ebe013f9..dc571f05 100644 --- a/SysCache2/NHibernate.Caches.SysCache2/NHibernate.Caches.SysCache2.csproj +++ b/SysCache2/NHibernate.Caches.SysCache2/NHibernate.Caches.SysCache2.csproj @@ -16,7 +16,7 @@ - + diff --git a/SysCache2/NHibernate.Caches.SysCache2/SysCacheProvider.cs b/SysCache2/NHibernate.Caches.SysCache2/SysCacheProvider.cs index a12647e5..42e092de 100644 --- a/SysCache2/NHibernate.Caches.SysCache2/SysCacheProvider.cs +++ b/SysCache2/NHibernate.Caches.SysCache2/SysCacheProvider.cs @@ -11,7 +11,8 @@ namespace NHibernate.Caches.SysCache2 public class SysCacheProvider : ICacheProvider { /// Pre-configured cache region settings. - private static readonly ConcurrentDictionary> CacheRegions = new ConcurrentDictionary>(); + private static readonly ConcurrentDictionary> CacheRegions = + new ConcurrentDictionary>(); /// List of pre configured already built cache regions. private static readonly Dictionary CacheRegionSettings; @@ -52,7 +53,9 @@ static SysCacheProvider() #region ICacheProvider Members /// +#pragma warning disable 618 public ICache BuildCache(string regionName, IDictionary properties) +#pragma warning restore 618 { // Return a configured cache region if we have one for the region already. // This may happen if there is a query cache specified for a region that is configured, @@ -70,7 +73,7 @@ public ICache BuildCache(string regionName, IDictionary properti // value after having obtained it, and it will not do that concurrently. // https://stackoverflow.com/a/31637510/1178314 var cache = CacheRegions.GetOrAdd(regionName, - r => new Lazy(() => BuildCache(r, properties, regionSettings))); + r => new Lazy(() => BuildCache(r, properties, regionSettings))); return cache.Value; } @@ -79,7 +82,7 @@ public ICache BuildCache(string regionName, IDictionary properti return BuildCache(regionName, properties, null); } - private ICache BuildCache(string regionName, IDictionary properties, CacheRegionElement settings) + private CacheBase BuildCache(string regionName, IDictionary properties, CacheRegionElement settings) { Log.Debug( settings != null diff --git a/SysCache2/NHibernate.Caches.SysCache2/SysCacheRegion.cs b/SysCache2/NHibernate.Caches.SysCache2/SysCacheRegion.cs index d715bdc4..25c1cd40 100644 --- a/SysCache2/NHibernate.Caches.SysCache2/SysCacheRegion.cs +++ b/SysCache2/NHibernate.Caches.SysCache2/SysCacheRegion.cs @@ -13,7 +13,7 @@ namespace NHibernate.Caches.SysCache2 /// /// Pluggable cache implementation using the System.Web.Caching classes and handling SQL dependencies. /// - public partial class SysCacheRegion : ICache + public class SysCacheRegion : CacheBase { /// The name of the cache prefix to differentiate the nhibernate cache elements from /// other items in the cache. @@ -94,10 +94,10 @@ public SysCacheRegion(string name, CacheRegionElement settings, IDictionary - public void Clear() + public override void Clear() { //remove the root cache item, this will cause all of the individual items to be removed from the cache _webCache.Remove(_rootCacheKey); @@ -107,13 +107,13 @@ public void Clear() } /// - public void Destroy() + public override void Destroy() { Clear(); } /// - public object Get(object key) + public override object Get(object key) { if (key == null || _isRootItemCached == false) { @@ -137,20 +137,21 @@ public object Get(object key) } /// - public void Lock(object key) + public override object Lock(object key) { //nothing to do here + return null; } /// - public long NextTimestamp() + public override long NextTimestamp() { return Timestamper.Next(); } /// [SuppressMessage("Microsoft.Reliability", "CA2000:DisposeObjectsBeforeLosingScope")] - public void Put(object key, object value) + public override void Put(object key, object value) { //validate the params if (key == null) @@ -207,10 +208,10 @@ public void Put(object key, object value) } /// - public string RegionName => _name; + public override string RegionName => _name; /// - public void Remove(object key) + public override void Remove(object key) { if (key == null) { @@ -226,10 +227,10 @@ public void Remove(object key) } /// - public int Timeout => Timestamper.OneMs * 60000; + public override int Timeout => Timestamper.OneMs * 60000; /// - public void Unlock(object key) + public override void Unlock(object key, object lockValue) { //nothing to do since we arent locking } diff --git a/Velocity/NHibernate.Caches.Velocity/Async/VelocityClient.cs b/Velocity/NHibernate.Caches.Velocity/Async/VelocityClient.cs deleted file mode 100644 index 97f05a0e..00000000 --- a/Velocity/NHibernate.Caches.Velocity/Async/VelocityClient.cs +++ /dev/null @@ -1,143 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -using System; -using System.Collections.Generic; -using System.Data.Caching; -using NHibernate.Cache; -using CacheException=System.Data.Caching.CacheException; -using CacheFactory=System.Data.Caching.CacheFactory; - -namespace NHibernate.Caches.Velocity -{ - using System.Threading.Tasks; - using System.Threading; - public partial class VelocityClient : ICache - { - - #region ICache Members - - /// - public Task GetAsync(object key, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(Get(key)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// - public Task PutAsync(object key, object value, CancellationToken cancellationToken) - { - if (key == null) - { - throw new ArgumentNullException("key", "null key not allowed"); - } - if (value == null) - { - throw new ArgumentNullException("value", "null value not allowed"); - } - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - Put(key, value); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// - public Task RemoveAsync(object key, CancellationToken cancellationToken) - { - if (key == null) - { - throw new ArgumentNullException("key"); - } - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - return InternalRemoveAsync(); - async Task InternalRemoveAsync() - { - log.Debug("removing item {0}", key); - - if (await (GetAsync(key.ToString(), cancellationToken)).ConfigureAwait(false) != null) - { - cache.Remove(region, key.ToString()); - } - } - } - - /// - public Task ClearAsync(CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - Clear(); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// - public async Task LockAsync(object key, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - var lockHandle = new LockHandle(); - if (await (GetAsync(key.ToString(), cancellationToken)).ConfigureAwait(false) != null) - { - try - { - cache.GetAndLock(region, key.ToString(), TimeSpan.FromMilliseconds(Timeout), out lockHandle); - } - catch (CacheException) {} - } - } - - /// - public async Task UnlockAsync(object key, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - var lockHandle = new LockHandle(); - if (await (GetAsync(key.ToString(), cancellationToken)).ConfigureAwait(false) != null) - { - try - { - cache.Unlock(region, key.ToString(), lockHandle); - } - catch (CacheException) {} - } - } - - #endregion - } -} diff --git a/Velocity/NHibernate.Caches.Velocity/NHibernate.Caches.Velocity.csproj b/Velocity/NHibernate.Caches.Velocity/NHibernate.Caches.Velocity.csproj index 0c63c415..957a2670 100644 --- a/Velocity/NHibernate.Caches.Velocity/NHibernate.Caches.Velocity.csproj +++ b/Velocity/NHibernate.Caches.Velocity/NHibernate.Caches.Velocity.csproj @@ -16,7 +16,7 @@ - + diff --git a/Velocity/NHibernate.Caches.Velocity/VelocityClient.cs b/Velocity/NHibernate.Caches.Velocity/VelocityClient.cs index f8807040..04c2b13d 100644 --- a/Velocity/NHibernate.Caches.Velocity/VelocityClient.cs +++ b/Velocity/NHibernate.Caches.Velocity/VelocityClient.cs @@ -46,7 +46,7 @@ namespace NHibernate.Caches.Velocity /// /// Pluggable cache implementation using the Velocity cache. /// - public partial class VelocityClient : ICache + public class VelocityClient : CacheBase { private const string CacheName = "nhibernate"; private static readonly INHibernateLogger log; @@ -86,10 +86,10 @@ public VelocityClient(string regionName, IDictionary properties) catch (CacheException) {} } - #region ICache Members + #region CacheBase Members /// - public object Get(object key) + public override object Get(object key) { if (key == null) { @@ -102,7 +102,7 @@ public object Get(object key) } /// - public void Put(object key, object value) + public override void Put(object key, object value) { if (key == null) { @@ -119,7 +119,7 @@ public void Put(object key, object value) } /// - public void Remove(object key) + public override void Remove(object key) { if (key == null) { @@ -134,19 +134,19 @@ public void Remove(object key) } /// - public void Clear() + public override void Clear() { cache.ClearRegion(region); } /// - public void Destroy() + public override void Destroy() { Clear(); } /// - public void Lock(object key) + public override object Lock(object key) { var lockHandle = new LockHandle(); if (Get(key.ToString()) != null) @@ -157,12 +157,14 @@ public void Lock(object key) } catch (CacheException) {} } + + return lockHandle; } /// - public void Unlock(object key) + public override void Unlock(object key, object lockValue) { - var lockHandle = new LockHandle(); + var lockHandle = lockValue as LockHandle? ?? new LockHandle(); if (Get(key.ToString()) != null) { try @@ -174,19 +176,19 @@ public void Unlock(object key) } /// - public long NextTimestamp() + public override long NextTimestamp() { return Timestamper.Next(); } /// - public int Timeout + public override int Timeout { get { return Timestamper.OneMs * 60000; } // 60 seconds } /// - public string RegionName + public override string RegionName { get { return region; } } diff --git a/Velocity/NHibernate.Caches.Velocity/VelocityProvider.cs b/Velocity/NHibernate.Caches.Velocity/VelocityProvider.cs index c50f8b9c..276cb471 100644 --- a/Velocity/NHibernate.Caches.Velocity/VelocityProvider.cs +++ b/Velocity/NHibernate.Caches.Velocity/VelocityProvider.cs @@ -58,7 +58,9 @@ static VelocityProvider() #region ICacheProvider Members /// +#pragma warning disable 618 public ICache BuildCache(string regionName, IDictionary properties) +#pragma warning restore 618 { if (regionName == null) { From e4ee15b116f13cf5bb21cfe13624a440f782d2f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Delaporte?= <12201973+fredericdelaporte@users.noreply.github.com> Date: Tue, 27 Nov 2018 14:47:33 +0100 Subject: [PATCH 2/3] Avoid binary breaking changes --- .../Async/CoreDistributedCache.cs | 7 +- .../CoreDistributedCache.cs | 105 +++++++++++++- .../CoreDistributedCacheProvider.cs | 2 +- .../CoreMemoryCache.cs | 125 ++++++++++++++++- .../MemCacheClient.cs | 129 ++++++++++++++++-- .../MemCacheClient.cs | 114 +++++++++++++++- .../PrevalenceCache.cs | 110 ++++++++++++++- .../RtMemoryCache.cs | 118 +++++++++++++++- .../SharedCacheClient.cs | 110 ++++++++++++++- .../NHibernate.Caches.SysCache/SysCache.cs | 123 ++++++++++++++++- .../SysCacheProviderFixture.cs | 4 +- .../SysCacheRegion.cs | 114 +++++++++++++++- .../VelocityClient.cs | 110 ++++++++++++++- 13 files changed, 1114 insertions(+), 57 deletions(-) diff --git a/CoreDistributedCache/NHibernate.Caches.CoreDistributedCache/Async/CoreDistributedCache.cs b/CoreDistributedCache/NHibernate.Caches.CoreDistributedCache/Async/CoreDistributedCache.cs index 23fb3866..39ed8a3c 100644 --- a/CoreDistributedCache/NHibernate.Caches.CoreDistributedCache/Async/CoreDistributedCache.cs +++ b/CoreDistributedCache/NHibernate.Caches.CoreDistributedCache/Async/CoreDistributedCache.cs @@ -13,15 +13,16 @@ using System.Collections.Generic; using System.IO; using System.Runtime.Serialization.Formatters.Binary; +using System.Threading; +using System.Threading.Tasks; using Microsoft.Extensions.Caching.Distributed; using NHibernate.Caches.Util; using NHibernate.Util; namespace NHibernate.Caches.CoreDistributedCache { - using System.Threading.Tasks; - using System.Threading; - public partial class CoreDistributedCache : CacheBase + + public abstract partial class CoreDistributedCacheBase : CacheBase { /// diff --git a/CoreDistributedCache/NHibernate.Caches.CoreDistributedCache/CoreDistributedCache.cs b/CoreDistributedCache/NHibernate.Caches.CoreDistributedCache/CoreDistributedCache.cs index 2019a10a..c5924b98 100644 --- a/CoreDistributedCache/NHibernate.Caches.CoreDistributedCache/CoreDistributedCache.cs +++ b/CoreDistributedCache/NHibernate.Caches.CoreDistributedCache/CoreDistributedCache.cs @@ -25,16 +25,115 @@ using System.Collections.Generic; using System.IO; using System.Runtime.Serialization.Formatters.Binary; +using System.Threading; +using System.Threading.Tasks; using Microsoft.Extensions.Caching.Distributed; using NHibernate.Caches.Util; using NHibernate.Util; namespace NHibernate.Caches.CoreDistributedCache { + // 6.0 TODO: replace that class by its base /// /// Pluggable cache implementation using implementations. /// - public partial class CoreDistributedCache : CacheBase + public class CoreDistributedCache : CoreDistributedCacheBase, +#pragma warning disable 618 + ICache +#pragma warning restore 618 + { + /// + /// Default constructor. + /// + /// The instance to use. + /// Optional constraints of . + /// The region of the cache. + /// Cache configuration properties. + /// + /// There are three (3) configurable parameters taken in : + ///
    + ///
  • expiration (or cache.default_expiration) = number of seconds to wait before expiring each item.
  • + ///
  • cache.use_sliding_expiration = a boolean, true for resetting a cached item expiration each time it is accessed.
  • + ///
  • regionPrefix = a string for prefixing the region name.
  • + ///
+ /// All parameters are optional. The defaults are an expiration of 300 seconds, no sliding expiration and no prefix. + ///
+ /// The "expiration" property could not be parsed. + [CLSCompliant(false)] + public CoreDistributedCache( + IDistributedCache cache, CacheConstraints constraints, string region, + IDictionary properties) + : base(cache, constraints, region, properties) + { + } + + /// + public new Task GetAsync(object key, CancellationToken cancellationToken) + => base.GetAsync(key, cancellationToken); + + /// + public new Task PutAsync(object key, object value, CancellationToken cancellationToken) + => base.PutAsync(key, value, cancellationToken); + + /// + public new Task RemoveAsync(object key, CancellationToken cancellationToken) + => base.RemoveAsync(key, cancellationToken); + + /// + public new Task ClearAsync(CancellationToken cancellationToken) + => base.ClearAsync(cancellationToken); + + /// + public new Task LockAsync(object key, CancellationToken cancellationToken) + => base.LockAsync(key, cancellationToken); + + /// + public Task UnlockAsync(object key, CancellationToken cancellationToken) + => base.UnlockAsync(key, null, cancellationToken); + + /// + public new string RegionName => base.RegionName; + + /// + public new object Get(object key) + => base.Get(key); + + /// + public new void Put(object key, object value) + => base.Put(key, value); + + /// + public new void Remove(object key) + => base.Remove(key); + + /// + public new void Clear() + => base.Clear(); + + /// + public new void Destroy() + => base.Destroy(); + + /// + public new void Lock(object key) + => base.Lock(key); + + /// + public void Unlock(object key) + => base.Unlock(key, null); + + /// + public new long NextTimestamp() + => base.NextTimestamp(); + + /// + public new int Timeout => base.Timeout; + } + + /// + /// Pluggable cache implementation using implementations. + /// + public abstract partial class CoreDistributedCacheBase : CacheBase { private static readonly INHibernateLogger Log = NHibernateLogger.For(typeof(CoreDistributedCache)); @@ -69,7 +168,7 @@ public partial class CoreDistributedCache : CacheBase /// /// The "expiration" property could not be parsed. [CLSCompliant(false)] - public CoreDistributedCache( + public CoreDistributedCacheBase( IDistributedCache cache, CacheConstraints constraints, string region, IDictionary properties) { if (constraints?.MaxKeySize <= 0) @@ -102,7 +201,7 @@ public CoreDistributedCache( /// This option is a workaround for distinguishing composite-id missing an /// override. It may causes trouble if the cache is shared /// between processes running another runtime than .Net Framework, or with future versions - /// of .Net Framework: the hascode is not guaranteed to be stable. + /// of .Net Framework: the hashcode is not guaranteed to be stable. /// /// /// The value of this property can be set with the attribute append-hashcode of the diff --git a/CoreDistributedCache/NHibernate.Caches.CoreDistributedCache/CoreDistributedCacheProvider.cs b/CoreDistributedCache/NHibernate.Caches.CoreDistributedCache/CoreDistributedCacheProvider.cs index c5097187..b6d855d6 100644 --- a/CoreDistributedCache/NHibernate.Caches.CoreDistributedCache/CoreDistributedCacheProvider.cs +++ b/CoreDistributedCache/NHibernate.Caches.CoreDistributedCache/CoreDistributedCacheProvider.cs @@ -58,7 +58,7 @@ public class CoreDistributedCacheProvider : ICacheProvider /// This option is a workaround for distinguishing composite-id missing an /// override. It may causes trouble if the cache is shared /// between processes running another runtime than .Net Framework, or with future versions - /// of .Net Framework: the hascode is not guaranteed to be stable. + /// of .Net Framework: the hashcode is not guaranteed to be stable. /// /// /// Changes to this property affect only caches built after the change, and whose configuration node diff --git a/CoreMemoryCache/NHibernate.Caches.CoreMemoryCache/CoreMemoryCache.cs b/CoreMemoryCache/NHibernate.Caches.CoreMemoryCache/CoreMemoryCache.cs index 06312ef8..a3609cc5 100644 --- a/CoreMemoryCache/NHibernate.Caches.CoreMemoryCache/CoreMemoryCache.cs +++ b/CoreMemoryCache/NHibernate.Caches.CoreMemoryCache/CoreMemoryCache.cs @@ -24,12 +24,14 @@ using NHibernate.Cache; using System.Collections.Generic; using System.Threading; +using System.Threading.Tasks; using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Primitives; using NHibernate.Util; namespace NHibernate.Caches.CoreMemoryCache { + // 6.0 TODO: replace that class by its base /// /// Pluggable cache implementation using the Microsoft.Extensions.Caching.Memory classes. /// @@ -39,7 +41,120 @@ namespace NHibernate.Caches.CoreMemoryCache /// API does not have a suitable method for triggering compaction, and size of each /// cached entry has to be user provided, which API does not support. /// - public class CoreMemoryCache : CacheBase + public class CoreMemoryCache : CoreMemoryCacheBase, +#pragma warning disable 618 + ICache +#pragma warning restore 618 + { + /// + /// Default constructor. + /// + public CoreMemoryCache() + { + } + + /// + /// Constructor with no properties. + /// + /// The region of the cache. + public CoreMemoryCache(string region) + : base(region) + { + } + + /// + /// Full constructor. + /// + /// The region of the cache. + /// Cache configuration properties. + /// + /// There are three (3) configurable parameters: + ///
    + ///
  • expiration (or cache.default_expiration) = number of seconds to wait before expiring each item.
  • + ///
  • cache.use_sliding_expiration = a boolean, true for resetting a cached item expiration each time it is accessed.
  • + ///
  • regionPrefix = a string for prefixing the region name.
  • + ///
+ /// All parameters are optional. The defaults are an expiration of 300 seconds, no sliding expiration and no prefix. + ///
+ /// The "expiration" property could not be parsed. + public CoreMemoryCache(string region, IDictionary properties) + : base(region, properties) + { + } + + /// + public new Task GetAsync(object key, CancellationToken cancellationToken) + => base.GetAsync(key, cancellationToken); + + /// + public new Task PutAsync(object key, object value, CancellationToken cancellationToken) + => base.PutAsync(key, value, cancellationToken); + + /// + public new Task RemoveAsync(object key, CancellationToken cancellationToken) + => base.RemoveAsync(key, cancellationToken); + + /// + public new Task ClearAsync(CancellationToken cancellationToken) + => base.ClearAsync(cancellationToken); + + /// + public new Task LockAsync(object key, CancellationToken cancellationToken) + => base.LockAsync(key, cancellationToken); + + /// + public Task UnlockAsync(object key, CancellationToken cancellationToken) + => base.UnlockAsync(key, null, cancellationToken); + + /// + public new string RegionName => base.RegionName; + + /// + public new object Get(object key) + => base.Get(key); + + /// + public new void Put(object key, object value) + => base.Put(key, value); + + /// + public new void Remove(object key) + => base.Remove(key); + + /// + public new void Clear() + => base.Clear(); + + /// + public new void Destroy() + => base.Destroy(); + + /// + public new void Lock(object key) + => base.Lock(key); + + /// + public void Unlock(object key) + => base.Unlock(key, null); + + /// + public new long NextTimestamp() + => base.NextTimestamp(); + + /// + public new int Timeout => base.Timeout; + } + + /// + /// Pluggable cache implementation using the Microsoft.Extensions.Caching.Memory classes. + /// + /// + /// Priority is not configurable because it is un-usable: the compaction on memory pressure feature has been + /// removed from MemoryCache, only explicit compaction or size limit compaction may use priorities. But + /// API does not have a suitable method for triggering compaction, and size of each + /// cached entry has to be user provided, which API does not support. + /// + public abstract class CoreMemoryCacheBase : CacheBase { private static readonly INHibernateLogger Log = NHibernateLogger.For(typeof(CoreMemoryCache)); @@ -58,7 +173,7 @@ public class CoreMemoryCache : CacheBase private volatile CancellationTokenSource _clearToken = new CancellationTokenSource(); private readonly ReaderWriterLockSlim _clearTokenLock = new ReaderWriterLockSlim(); - static CoreMemoryCache() + static CoreMemoryCacheBase() { var cacheOption = new MemoryCacheOptions(); if (CoreMemoryCacheProvider.ExpirationScanFrequency.HasValue) @@ -72,7 +187,7 @@ static CoreMemoryCache() /// /// Default constructor. /// - public CoreMemoryCache() + public CoreMemoryCacheBase() : this("nhibernate", null) { } @@ -81,7 +196,7 @@ public CoreMemoryCache() /// Constructor with no properties. /// /// The region of the cache. - public CoreMemoryCache(string region) + public CoreMemoryCacheBase(string region) : this(region, null) { } @@ -101,7 +216,7 @@ public CoreMemoryCache(string region) /// All parameters are optional. The defaults are an expiration of 300 seconds, no sliding expiration and no prefix. /// /// The "expiration" property could not be parsed. - public CoreMemoryCache(string region, IDictionary properties) + public CoreMemoryCacheBase(string region, IDictionary properties) { RegionName = region; Configure(properties); diff --git a/EnyimMemcached/NHibernate.Caches.EnyimMemcached/MemCacheClient.cs b/EnyimMemcached/NHibernate.Caches.EnyimMemcached/MemCacheClient.cs index afec585c..b83f9bd6 100644 --- a/EnyimMemcached/NHibernate.Caches.EnyimMemcached/MemCacheClient.cs +++ b/EnyimMemcached/NHibernate.Caches.EnyimMemcached/MemCacheClient.cs @@ -1,6 +1,8 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; using Enyim.Caching; using Enyim.Caching.Memcached; using NHibernate.Cache; @@ -9,10 +11,121 @@ namespace NHibernate.Caches.EnyimMemcached { + // 6.0 TODO: replace that class by its base /// /// Pluggable cache implementation using Memcached and the EnyimMemcached client library. /// - public class MemCacheClient : CacheBase + public class MemCacheClient : MemCacheClientBase, +#pragma warning disable 618 + ICache +#pragma warning restore 618 + { + /// + /// Default constructor. + /// + public MemCacheClient() + { + } + + /// + /// Constructor with no properties. + /// + /// The region of the cache. + public MemCacheClient(string regionName) + : base(regionName) + { + } + + /// + /// Constructor with default Memcache client instance. + /// + /// The cache region name. + /// The configuration properties. + public MemCacheClient(string regionName, IDictionary properties) + : base(regionName, properties) + { + } + + /// + /// Full constructor. + /// + /// The cache region name. + /// The configuration properties. + /// The Memcache client. + [CLSCompliant(false)] + public MemCacheClient(string regionName, IDictionary properties, + MemcachedClient memcachedClient) + : base(regionName, properties, memcachedClient) + { + } + + /// + public new Task GetAsync(object key, CancellationToken cancellationToken) + => base.GetAsync(key, cancellationToken); + + /// + public new Task PutAsync(object key, object value, CancellationToken cancellationToken) + => base.PutAsync(key, value, cancellationToken); + + /// + public new Task RemoveAsync(object key, CancellationToken cancellationToken) + => base.RemoveAsync(key, cancellationToken); + + /// + public new Task ClearAsync(CancellationToken cancellationToken) + => base.ClearAsync(cancellationToken); + + /// + public new Task LockAsync(object key, CancellationToken cancellationToken) + => base.LockAsync(key, cancellationToken); + + /// + public Task UnlockAsync(object key, CancellationToken cancellationToken) + => base.UnlockAsync(key, null, cancellationToken); + + /// + public new string RegionName => base.RegionName; + + /// + public new object Get(object key) + => base.Get(key); + + /// + public new void Put(object key, object value) + => base.Put(key, value); + + /// + public new void Remove(object key) + => base.Remove(key); + + /// + public new void Clear() + => base.Clear(); + + /// + public new void Destroy() + => base.Destroy(); + + /// + public new void Lock(object key) + => base.Lock(key); + + /// + public void Unlock(object key) + => base.Unlock(key, null); + + /// + public new long NextTimestamp() + => base.NextTimestamp(); + + /// + public new int Timeout => base.Timeout; + } + + /// + /// Pluggable cache implementation using Memcached and the EnyimMemcached client library. + /// + public abstract class MemCacheClientBase : CacheBase { private static readonly INHibernateLogger log; @@ -24,7 +137,7 @@ public class MemCacheClient : CacheBase private const int _maxKeySize = 249; - static MemCacheClient() + static MemCacheClientBase() { log = NHibernateLogger.For(typeof(MemCacheClient)); } @@ -32,16 +145,16 @@ static MemCacheClient() /// /// Default constructor. /// - public MemCacheClient() + public MemCacheClientBase() : this("nhibernate", null) { } /// - /// Contructor with no properties. + /// Constructor with no properties. /// /// The cache region name. - public MemCacheClient(string regionName) + public MemCacheClientBase(string regionName) : this(regionName, null) { } @@ -51,7 +164,7 @@ public MemCacheClient(string regionName) /// /// The cache region name. /// The configuration properties. - public MemCacheClient(string regionName, IDictionary properties) + public MemCacheClientBase(string regionName, IDictionary properties) : this(regionName, properties, new MemcachedClient()) { } @@ -63,7 +176,7 @@ public MemCacheClient(string regionName, IDictionary properties) /// The configuration properties. /// The Memcache client. [CLSCompliant(false)] - public MemCacheClient(string regionName, IDictionary properties, MemcachedClient memcachedClient) + public MemCacheClientBase(string regionName, IDictionary properties, MemcachedClient memcachedClient) { region = regionName; @@ -208,7 +321,7 @@ private static string GetExpirationString(IDictionary props) } /// - /// Turn the key obj into a string, preperably using human readable + /// Turn the key obj into a string, preferably using human readable /// string, and if the string is too long (> _maxKeySize) it will be hashed /// private string KeyAsString(object key) diff --git a/MemCache/NHibernate.Caches.MemCache/MemCacheClient.cs b/MemCache/NHibernate.Caches.MemCache/MemCacheClient.cs index db631106..e0132bd3 100644 --- a/MemCache/NHibernate.Caches.MemCache/MemCacheClient.cs +++ b/MemCache/NHibernate.Caches.MemCache/MemCacheClient.cs @@ -27,16 +27,116 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; using Memcached.ClientLibrary; using NHibernate.Cache; using NHibernate.Caches.Util; namespace NHibernate.Caches.MemCache { + // 6.0 TODO: replace that class by its base /// /// Pluggable cache implementation using Memcached. /// - public class MemCacheClient : CacheBase + public class MemCacheClient : MemCacheClientBase, +#pragma warning disable 618 + ICache +#pragma warning restore 618 + { + /// + /// Default constructor. + /// + public MemCacheClient() + { + } + + /// + /// Constructor with no properties. + /// + /// The region of the cache. + public MemCacheClient(string regionName) + : base(regionName) + { + } + + /// + /// Full constructor. + /// + /// The cache region name. + /// The configuration properties. + public MemCacheClient(string regionName, IDictionary properties) + : base(regionName, properties) + { + } + + /// + public new Task GetAsync(object key, CancellationToken cancellationToken) + => base.GetAsync(key, cancellationToken); + + /// + public new Task PutAsync(object key, object value, CancellationToken cancellationToken) + => base.PutAsync(key, value, cancellationToken); + + /// + public new Task RemoveAsync(object key, CancellationToken cancellationToken) + => base.RemoveAsync(key, cancellationToken); + + /// + public new Task ClearAsync(CancellationToken cancellationToken) + => base.ClearAsync(cancellationToken); + + /// + public new Task LockAsync(object key, CancellationToken cancellationToken) + => base.LockAsync(key, cancellationToken); + + /// + public Task UnlockAsync(object key, CancellationToken cancellationToken) + => base.UnlockAsync(key, null, cancellationToken); + + /// + public new string RegionName => base.RegionName; + + /// + public new object Get(object key) + => base.Get(key); + + /// + public new void Put(object key, object value) + => base.Put(key, value); + + /// + public new void Remove(object key) + => base.Remove(key); + + /// + public new void Clear() + => base.Clear(); + + /// + public new void Destroy() + => base.Destroy(); + + /// + public new void Lock(object key) + => base.Lock(key); + + /// + public void Unlock(object key) + => base.Unlock(key, null); + + /// + public new long NextTimestamp() + => base.NextTimestamp(); + + /// + public new int Timeout => base.Timeout; + } + + /// + /// Pluggable cache implementation using Memcached. + /// + public abstract class MemCacheClientBase : CacheBase { internal const string PoolName = "nhibernate"; private static readonly INHibernateLogger log; @@ -50,7 +150,7 @@ public class MemCacheClient : CacheBase private const int _maxKeySize = 249; - static MemCacheClient() + static MemCacheClientBase() { log = NHibernateLogger.For(typeof(MemCacheClient)); } @@ -58,15 +158,15 @@ static MemCacheClient() /// /// Default constructor. /// - public MemCacheClient() : this("nhibernate", null) + public MemCacheClientBase() : this("nhibernate", null) { } /// - /// Contructor with no properties. + /// Constructor with no properties. /// /// The cache region name. - public MemCacheClient(string regionName) : this(regionName, null) + public MemCacheClientBase(string regionName) : this(regionName, null) { } @@ -75,7 +175,7 @@ public MemCacheClient(string regionName) : this(regionName, null) /// /// The cache region name. /// The configuration properties. - public MemCacheClient(string regionName, IDictionary properties) + public MemCacheClientBase(string regionName, IDictionary properties) { region = regionName; client = new MemcachedClient { PoolName = PoolName }; @@ -236,7 +336,7 @@ public override string RegionName #endregion /// - /// Turn the key obj into a string, preperably using human readable + /// Turn the key obj into a string, preferably using human readable /// string, and if the string is too long (>_maxKeySize) it will be hashed /// private string KeyAsString(object key) diff --git a/Prevalence/NHibernate.Caches.Prevalence/PrevalenceCache.cs b/Prevalence/NHibernate.Caches.Prevalence/PrevalenceCache.cs index 90717e7e..f59277da 100644 --- a/Prevalence/NHibernate.Caches.Prevalence/PrevalenceCache.cs +++ b/Prevalence/NHibernate.Caches.Prevalence/PrevalenceCache.cs @@ -1,13 +1,113 @@ using System; using System.Collections; +using System.Threading; +using System.Threading.Tasks; using NHibernate.Cache; namespace NHibernate.Caches.Prevalence { + // 6.0 TODO: replace that class by its base /// /// Pluggable cache implementation using Bamboo Prevalence. /// - public class PrevalenceCache : CacheBase + public class PrevalenceCache : PrevalenceCacheBase, +#pragma warning disable 618 + ICache +#pragma warning restore 618 + { + /// + /// Default constructor. + /// + public PrevalenceCache() + { + } + + /// + /// Constructor with no properties. + /// + /// The region of the cache. + public PrevalenceCache(string region) + : base(region) + { + } + + /// + /// Full constructor. + /// + /// The cache region name. + /// The Prevalance container class. + public PrevalenceCache(string region, CacheSystem system) + : base(region, system) + { + } + + /// + public new Task GetAsync(object key, CancellationToken cancellationToken) + => base.GetAsync(key, cancellationToken); + + /// + public new Task PutAsync(object key, object value, CancellationToken cancellationToken) + => base.PutAsync(key, value, cancellationToken); + + /// + public new Task RemoveAsync(object key, CancellationToken cancellationToken) + => base.RemoveAsync(key, cancellationToken); + + /// + public new Task ClearAsync(CancellationToken cancellationToken) + => base.ClearAsync(cancellationToken); + + /// + public new Task LockAsync(object key, CancellationToken cancellationToken) + => base.LockAsync(key, cancellationToken); + + /// + public Task UnlockAsync(object key, CancellationToken cancellationToken) + => base.UnlockAsync(key, null, cancellationToken); + + /// + public new string RegionName => base.RegionName; + + /// + public new object Get(object key) + => base.Get(key); + + /// + public new void Put(object key, object value) + => base.Put(key, value); + + /// + public new void Remove(object key) + => base.Remove(key); + + /// + public new void Clear() + => base.Clear(); + + /// + public new void Destroy() + => base.Destroy(); + + /// + public new void Lock(object key) + => base.Lock(key); + + /// + public void Unlock(object key) + => base.Unlock(key, null); + + /// + public new long NextTimestamp() + => base.NextTimestamp(); + + /// + public new int Timeout => base.Timeout; + } + + /// + /// Pluggable cache implementation using Bamboo Prevalence. + /// + public abstract class PrevalenceCacheBase : CacheBase { private const string CacheKeyPrefix = "NHibernate-Cache:"; private static readonly INHibernateLogger log = NHibernateLogger.For(typeof(PrevalenceCache)); @@ -17,20 +117,20 @@ public class PrevalenceCache : CacheBase /// /// Default constructor. /// - public PrevalenceCache() : this("nhibernate", null) {} + public PrevalenceCacheBase() : this("nhibernate", null) {} /// - /// Contructor with no properties. + /// Constructor with no properties. /// /// The cache region name. - public PrevalenceCache(string region) : this(region, null) {} + public PrevalenceCacheBase(string region) : this(region, null) {} /// /// Full constructor. /// /// The cache region name. /// The Prevalance container class. - public PrevalenceCache(string region, CacheSystem system) + public PrevalenceCacheBase(string region, CacheSystem system) { this.region = region; this.system = system ?? new CacheSystem(); diff --git a/RtMemoryCache/NHibernate.Caches.RtMemoryCache/RtMemoryCache.cs b/RtMemoryCache/NHibernate.Caches.RtMemoryCache/RtMemoryCache.cs index 1413a704..2aa13b10 100644 --- a/RtMemoryCache/NHibernate.Caches.RtMemoryCache/RtMemoryCache.cs +++ b/RtMemoryCache/NHibernate.Caches.RtMemoryCache/RtMemoryCache.cs @@ -25,14 +25,124 @@ using System.Runtime.Caching; using NHibernate.Cache; using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; using NHibernate.Util; namespace NHibernate.Caches.RtMemoryCache { + // 6.0 TODO: replace that class by its base /// /// Pluggable cache implementation using the System.Runtime.Caching classes. /// - public class RtMemoryCache : CacheBase + public class RtMemoryCache : RtMemoryCacheBase, +#pragma warning disable 618 + ICache +#pragma warning restore 618 + { + /// + /// Default constructor. + /// + public RtMemoryCache() + { + } + + /// + /// Constructor with no properties. + /// + /// The region of the cache. + public RtMemoryCache(string region) + : base(region) + { + } + + /// + /// Full constructor. + /// + /// The cache region name. + /// The cache configuration properties. + /// + /// There are three (3) configurable parameters: + ///
    + ///
  • expiration (or cache.default_expiration) = number of seconds to wait before expiring each item.
  • + ///
  • cache.use_sliding_expiration = a boolean, true for resetting a cached item expiration each time it is accessed.
  • + ///
  • regionPrefix = a string for prefixing the region name.
  • + ///
+ /// All parameters are optional. The defaults are an expiration of 300 seconds, no sliding expiration, no region prefix. + ///
+ /// The "expiration" property could not be parsed. + public RtMemoryCache(string region, IDictionary properties) + : base(region, properties) + { + } + + /// + public new Task GetAsync(object key, CancellationToken cancellationToken) + => base.GetAsync(key, cancellationToken); + + /// + public new Task PutAsync(object key, object value, CancellationToken cancellationToken) + => base.PutAsync(key, value, cancellationToken); + + /// + public new Task RemoveAsync(object key, CancellationToken cancellationToken) + => base.RemoveAsync(key, cancellationToken); + + /// + public new Task ClearAsync(CancellationToken cancellationToken) + => base.ClearAsync(cancellationToken); + + /// + public new Task LockAsync(object key, CancellationToken cancellationToken) + => base.LockAsync(key, cancellationToken); + + /// + public Task UnlockAsync(object key, CancellationToken cancellationToken) + => base.UnlockAsync(key, null, cancellationToken); + + /// + public new string RegionName => base.RegionName; + + /// + public new object Get(object key) + => base.Get(key); + + /// + public new void Put(object key, object value) + => base.Put(key, value); + + /// + public new void Remove(object key) + => base.Remove(key); + + /// + public new void Clear() + => base.Clear(); + + /// + public new void Destroy() + => base.Destroy(); + + /// + public new void Lock(object key) + => base.Lock(key); + + /// + public void Unlock(object key) + => base.Unlock(key, null); + + /// + public new long NextTimestamp() + => base.NextTimestamp(); + + /// + public new int Timeout => base.Timeout; + } + + /// + /// Pluggable cache implementation using the System.Runtime.Caching classes. + /// + public abstract class RtMemoryCacheBase : CacheBase { private static readonly INHibernateLogger Log = NHibernateLogger.For(typeof(RtMemoryCache)); private string _regionPrefix; @@ -49,7 +159,7 @@ public class RtMemoryCache : CacheBase /// /// Default constructor. /// - public RtMemoryCache() + public RtMemoryCacheBase() : this("nhibernate", null) { } @@ -58,7 +168,7 @@ public RtMemoryCache() /// Constructor with no properties. /// /// The cache region name. - public RtMemoryCache(string region) + public RtMemoryCacheBase(string region) : this(region, null) { } @@ -78,7 +188,7 @@ public RtMemoryCache(string region) /// All parameters are optional. The defaults are an expiration of 300 seconds, no sliding expiration, no region prefix. /// /// The "expiration" property could not be parsed. - public RtMemoryCache(string region, IDictionary properties) + public RtMemoryCacheBase(string region, IDictionary properties) { Region = region; _cache = MemoryCache.Default; diff --git a/SharedCache/NHibernate.Caches.SharedCache/SharedCacheClient.cs b/SharedCache/NHibernate.Caches.SharedCache/SharedCacheClient.cs index 904eaa97..4148b9e9 100644 --- a/SharedCache/NHibernate.Caches.SharedCache/SharedCacheClient.cs +++ b/SharedCache/NHibernate.Caches.SharedCache/SharedCacheClient.cs @@ -25,20 +25,120 @@ using System; using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; using MergeSystem.Indexus.WinServiceCommon.Provider.Cache; using NHibernate.Cache; namespace NHibernate.Caches.SharedCache { + // 6.0 TODO: replace that class by its base /// /// Pluggable cache implementation using indeXus.Net Shared Cache. /// - public class SharedCacheClient : CacheBase + public class SharedCacheClient : SharedCacheClientBase, +#pragma warning disable 618 + ICache +#pragma warning restore 618 + { + /// + /// Default constructor. + /// + public SharedCacheClient() + { + } + + /// + /// Constructor with no properties. + /// + /// The region of the cache. + public SharedCacheClient(string regionName) + : base(regionName) + { + } + + /// + /// Full constructor. + /// + /// The cache region name. + /// The configuration properties. + public SharedCacheClient(string regionName, IDictionary properties) + : base(regionName, properties) + { + } + + /// + public new Task GetAsync(object key, CancellationToken cancellationToken) + => base.GetAsync(key, cancellationToken); + + /// + public new Task PutAsync(object key, object value, CancellationToken cancellationToken) + => base.PutAsync(key, value, cancellationToken); + + /// + public new Task RemoveAsync(object key, CancellationToken cancellationToken) + => base.RemoveAsync(key, cancellationToken); + + /// + public new Task ClearAsync(CancellationToken cancellationToken) + => base.ClearAsync(cancellationToken); + + /// + public new Task LockAsync(object key, CancellationToken cancellationToken) + => base.LockAsync(key, cancellationToken); + + /// + public Task UnlockAsync(object key, CancellationToken cancellationToken) + => base.UnlockAsync(key, null, cancellationToken); + + /// + public new string RegionName => base.RegionName; + + /// + public new object Get(object key) + => base.Get(key); + + /// + public new void Put(object key, object value) + => base.Put(key, value); + + /// + public new void Remove(object key) + => base.Remove(key); + + /// + public new void Clear() + => base.Clear(); + + /// + public new void Destroy() + => base.Destroy(); + + /// + public new void Lock(object key) + => base.Lock(key); + + /// + public void Unlock(object key) + => base.Unlock(key, null); + + /// + public new long NextTimestamp() + => base.NextTimestamp(); + + /// + public new int Timeout => base.Timeout; + } + + /// + /// Pluggable cache implementation using indeXus.Net Shared Cache. + /// + public abstract class SharedCacheClientBase : CacheBase { private static readonly INHibernateLogger log; private readonly string region; - static SharedCacheClient() + static SharedCacheClientBase() { log = NHibernateLogger.For(typeof(SharedCacheClient)); } @@ -46,20 +146,20 @@ static SharedCacheClient() /// /// Default constructor. /// - public SharedCacheClient() : this("nhibernate", null) {} + public SharedCacheClientBase() : this("nhibernate", null) {} /// /// Constructor with no properties. /// /// The cache region name. - public SharedCacheClient(string regionName) : this(regionName, null) {} + public SharedCacheClientBase(string regionName) : this(regionName, null) {} /// /// Full constructor. /// /// The cache region name. /// The cache configuration properties. - public SharedCacheClient(string regionName, IDictionary properties) + public SharedCacheClientBase(string regionName, IDictionary properties) { region = regionName; diff --git a/SysCache/NHibernate.Caches.SysCache/SysCache.cs b/SysCache/NHibernate.Caches.SysCache/SysCache.cs index 9d630b25..aa387985 100644 --- a/SysCache/NHibernate.Caches.SysCache/SysCache.cs +++ b/SysCache/NHibernate.Caches.SysCache/SysCache.cs @@ -26,14 +26,129 @@ using System.Web.Caching; using NHibernate.Cache; using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; using NHibernate.Util; namespace NHibernate.Caches.SysCache { + // 6.0 TODO: replace that class by its base /// /// Pluggable cache implementation using the System.Web.Caching classes. /// - public class SysCache : CacheBase + public class SysCache : SysCacheBase, +#pragma warning disable 618 + ICache +#pragma warning restore 618 + { + /// + /// Default constructor. + /// + public SysCache() + { + } + + /// + /// Constructor with no properties. + /// + /// The region of the cache. + public SysCache(string region) + : base(region) + { + } + + /// + /// Full constructor. + /// + /// The cache region name. + /// The cache configuration properties. + /// + /// There are four (4) configurable parameters: + ///
    + ///
  • expiration (or cache.default_expiration) = number of seconds to wait before expiring each item
  • + ///
  • cache.use_sliding_expiration = a boolean, true for resetting a cached item expiration each time it is accessed.
  • + ///
  • regionPrefix = a string for prefixing the region name.
  • + ///
  • priority = a numeric cost of expiring each item, where 1 is a low cost, 6 is the highest, and 3 is + /// normal. Only values 1 through 6 are valid. 6 should be avoided, this value is the + /// priority.
  • + ///
+ /// All parameters are optional. The defaults are an expiration of 300 seconds, no sliding expiration, no region + /// prefix and the default priority of 3. + ///
+ /// The "priority" property is not between 1 and 6 + /// The "expiration" property could not be parsed. + public SysCache(string region, IDictionary properties) + : base(region, properties) + { + } + + /// + public new Task GetAsync(object key, CancellationToken cancellationToken) + => base.GetAsync(key, cancellationToken); + + /// + public new Task PutAsync(object key, object value, CancellationToken cancellationToken) + => base.PutAsync(key, value, cancellationToken); + + /// + public new Task RemoveAsync(object key, CancellationToken cancellationToken) + => base.RemoveAsync(key, cancellationToken); + + /// + public new Task ClearAsync(CancellationToken cancellationToken) + => base.ClearAsync(cancellationToken); + + /// + public new Task LockAsync(object key, CancellationToken cancellationToken) + => base.LockAsync(key, cancellationToken); + + /// + public Task UnlockAsync(object key, CancellationToken cancellationToken) + => base.UnlockAsync(key, null, cancellationToken); + + /// + public new string RegionName => base.RegionName; + + /// + public new object Get(object key) + => base.Get(key); + + /// + public new void Put(object key, object value) + => base.Put(key, value); + + /// + public new void Remove(object key) + => base.Remove(key); + + /// + public new void Clear() + => base.Clear(); + + /// + public new void Destroy() + => base.Destroy(); + + /// + public new void Lock(object key) + => base.Lock(key); + + /// + public void Unlock(object key) + => base.Unlock(key, null); + + /// + public new long NextTimestamp() + => base.NextTimestamp(); + + /// + public new int Timeout => base.Timeout; + } + + /// + /// Pluggable cache implementation using the System.Web.Caching classes. + /// + public abstract class SysCacheBase : CacheBase { private static readonly INHibernateLogger Log = NHibernateLogger.For(typeof(SysCache)); private string _regionPrefix; @@ -51,7 +166,7 @@ public class SysCache : CacheBase /// /// Default constructor. /// - public SysCache() + public SysCacheBase() : this("nhibernate", null) { } @@ -60,7 +175,7 @@ public SysCache() /// Constructor with no properties. /// /// The cache region name. - public SysCache(string region) + public SysCacheBase(string region) : this(region, null) { } @@ -85,7 +200,7 @@ public SysCache(string region) /// /// The "priority" property is not between 1 and 6 /// The "expiration" property could not be parsed. - public SysCache(string region, IDictionary properties) + public SysCacheBase(string region, IDictionary properties) { Region = region; _cache = HttpRuntime.Cache; diff --git a/SysCache2/NHibernate.Caches.SysCache2.Tests/SysCacheProviderFixture.cs b/SysCache2/NHibernate.Caches.SysCache2.Tests/SysCacheProviderFixture.cs index b8cea81c..422b802b 100644 --- a/SysCache2/NHibernate.Caches.SysCache2.Tests/SysCacheProviderFixture.cs +++ b/SysCache2/NHibernate.Caches.SysCache2.Tests/SysCacheProviderFixture.cs @@ -53,10 +53,10 @@ public void TestBuildCacheFromConfig() } private static readonly FieldInfo RelativeExpirationField = - typeof(SysCacheRegion).GetField("_relativeExpiration", BindingFlags.NonPublic | BindingFlags.Instance); + typeof(SysCacheRegionBase).GetField("_relativeExpiration", BindingFlags.NonPublic | BindingFlags.Instance); private static readonly FieldInfo UseSlidingExpirationField = - typeof(SysCacheRegion).GetField("_useSlidingExpiration", BindingFlags.NonPublic | BindingFlags.Instance); + typeof(SysCacheRegionBase).GetField("_useSlidingExpiration", BindingFlags.NonPublic | BindingFlags.Instance); [Test] public void TestExpiration() diff --git a/SysCache2/NHibernate.Caches.SysCache2/SysCacheRegion.cs b/SysCache2/NHibernate.Caches.SysCache2/SysCacheRegion.cs index 25c1cd40..2f012704 100644 --- a/SysCache2/NHibernate.Caches.SysCache2/SysCacheRegion.cs +++ b/SysCache2/NHibernate.Caches.SysCache2/SysCacheRegion.cs @@ -2,6 +2,8 @@ using System.Collections; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; +using System.Threading; +using System.Threading.Tasks; using System.Web; using System.Web.Caching; using NHibernate.Cache; @@ -10,10 +12,112 @@ namespace NHibernate.Caches.SysCache2 { + // 6.0 TODO: replace that class by its base /// /// Pluggable cache implementation using the System.Web.Caching classes and handling SQL dependencies. /// - public class SysCacheRegion : CacheBase + public class SysCacheRegion : SysCacheRegionBase, +#pragma warning disable 618 + ICache +#pragma warning restore 618 + { + /// + /// Default constructor. + /// + public SysCacheRegion() + { + } + + /// + /// Initializes a new instance of the class with the default configuration + /// properties. + /// + /// The name of the region. + /// Additional NHibernate configuration properties. + public SysCacheRegion(string name, IDictionary additionalProperties) + : base(name, additionalProperties) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The name of the region. + /// The configuration settings for the cache region. + /// Additional NHibernate configuration properties. + public SysCacheRegion(string name, CacheRegionElement settings, + IDictionary additionalProperties) + : base(name, settings, additionalProperties) + { + } + + /// + public new Task GetAsync(object key, CancellationToken cancellationToken) + => base.GetAsync(key, cancellationToken); + + /// + public new Task PutAsync(object key, object value, CancellationToken cancellationToken) + => base.PutAsync(key, value, cancellationToken); + + /// + public new Task RemoveAsync(object key, CancellationToken cancellationToken) + => base.RemoveAsync(key, cancellationToken); + + /// + public new Task ClearAsync(CancellationToken cancellationToken) + => base.ClearAsync(cancellationToken); + + /// + public new Task LockAsync(object key, CancellationToken cancellationToken) + => base.LockAsync(key, cancellationToken); + + /// + public Task UnlockAsync(object key, CancellationToken cancellationToken) + => base.UnlockAsync(key, null, cancellationToken); + + /// + public new string RegionName => base.RegionName; + + /// + public new object Get(object key) + => base.Get(key); + + /// + public new void Put(object key, object value) + => base.Put(key, value); + + /// + public new void Remove(object key) + => base.Remove(key); + + /// + public new void Clear() + => base.Clear(); + + /// + public new void Destroy() + => base.Destroy(); + + /// + public new void Lock(object key) + => base.Lock(key); + + /// + public void Unlock(object key) + => base.Unlock(key, null); + + /// + public new long NextTimestamp() + => base.NextTimestamp(); + + /// + public new int Timeout => base.Timeout; + } + + /// + /// Pluggable cache implementation using the System.Web.Caching classes and handling SQL dependencies. + /// + public abstract class SysCacheRegionBase : CacheBase { /// The name of the cache prefix to differentiate the nhibernate cache elements from /// other items in the cache. @@ -57,7 +161,7 @@ public class SysCacheRegion : CacheBase /// Initializes a new instance of the class with /// the default region name and configuration properties. /// - public SysCacheRegion() : this(null, null, null) {} + public SysCacheRegionBase() : this(null, null, null) {} /// /// Initializes a new instance of the class with the default configuration @@ -65,7 +169,7 @@ public SysCacheRegion() : this(null, null, null) {} /// /// The name of the region. /// Additional NHibernate configuration properties. - public SysCacheRegion(string name, IDictionary additionalProperties) + public SysCacheRegionBase(string name, IDictionary additionalProperties) : this(name, null, additionalProperties) {} /// @@ -74,7 +178,7 @@ public SysCacheRegion(string name, IDictionary additionalPropert /// The name of the region. /// The configuration settings for the cache region. /// Additional NHibernate configuration properties. - public SysCacheRegion(string name, CacheRegionElement settings, IDictionary additionalProperties) + public SysCacheRegionBase(string name, CacheRegionElement settings, IDictionary additionalProperties) { //validate the params if (string.IsNullOrEmpty(name)) @@ -485,7 +589,7 @@ private void CacheRootItem() /// /// Called when the root cache item has been removed from the cache. /// - /// The key of the cache item that wwas removed. + /// The key of the cache item that was removed. /// The value of the cache item that was removed. /// The for the removal of the /// item from the cache. diff --git a/Velocity/NHibernate.Caches.Velocity/VelocityClient.cs b/Velocity/NHibernate.Caches.Velocity/VelocityClient.cs index 04c2b13d..5b63ddc5 100644 --- a/Velocity/NHibernate.Caches.Velocity/VelocityClient.cs +++ b/Velocity/NHibernate.Caches.Velocity/VelocityClient.cs @@ -37,23 +37,123 @@ using System; using System.Collections.Generic; using System.Data.Caching; +using System.Threading; +using System.Threading.Tasks; using NHibernate.Cache; using CacheException=System.Data.Caching.CacheException; using CacheFactory=System.Data.Caching.CacheFactory; namespace NHibernate.Caches.Velocity { + // 6.0 TODO: replace that class by its base /// /// Pluggable cache implementation using the Velocity cache. /// - public class VelocityClient : CacheBase + public class VelocityClient : VelocityClientBase, +#pragma warning disable 618 + ICache +#pragma warning restore 618 + { + /// + /// Default constructor. + /// + public VelocityClient() + { + } + + /// + /// Constructor with no properties. + /// + /// The region of the cache. + public VelocityClient(string regionName) + : base(regionName) + { + } + + /// + /// Full constructor. + /// + /// The cache region name. + /// The configuration properties. + public VelocityClient(string regionName, IDictionary properties) + : base(regionName, properties) + { + } + + /// + public new Task GetAsync(object key, CancellationToken cancellationToken) + => base.GetAsync(key, cancellationToken); + + /// + public new Task PutAsync(object key, object value, CancellationToken cancellationToken) + => base.PutAsync(key, value, cancellationToken); + + /// + public new Task RemoveAsync(object key, CancellationToken cancellationToken) + => base.RemoveAsync(key, cancellationToken); + + /// + public new Task ClearAsync(CancellationToken cancellationToken) + => base.ClearAsync(cancellationToken); + + /// + public new Task LockAsync(object key, CancellationToken cancellationToken) + => base.LockAsync(key, cancellationToken); + + /// + public Task UnlockAsync(object key, CancellationToken cancellationToken) + => base.UnlockAsync(key, null, cancellationToken); + + /// + public new string RegionName => base.RegionName; + + /// + public new object Get(object key) + => base.Get(key); + + /// + public new void Put(object key, object value) + => base.Put(key, value); + + /// + public new void Remove(object key) + => base.Remove(key); + + /// + public new void Clear() + => base.Clear(); + + /// + public new void Destroy() + => base.Destroy(); + + /// + public new void Lock(object key) + => base.Lock(key); + + /// + public void Unlock(object key) + => base.Unlock(key, null); + + /// + public new long NextTimestamp() + => base.NextTimestamp(); + + /// + public new int Timeout => base.Timeout; + } + + /// + /// Pluggable cache implementation using the Velocity cache. + /// + public abstract class VelocityClientBase : CacheBase { private const string CacheName = "nhibernate"; private static readonly INHibernateLogger log; private readonly System.Data.Caching.Cache cache; private readonly string region; - static VelocityClient() + static VelocityClientBase() { log = NHibernateLogger.For(typeof(VelocityClient)); } @@ -61,20 +161,20 @@ static VelocityClient() /// /// Default constructor. /// - public VelocityClient() : this("nhibernate", null) {} + public VelocityClientBase() : this("nhibernate", null) {} /// /// Constructor with no properties. /// /// The cache region name. - public VelocityClient(string regionName) : this(regionName, null) {} + public VelocityClientBase(string regionName) : this(regionName, null) {} /// /// Full constructor. /// /// The cache region name. /// The cache configuration properties. - public VelocityClient(string regionName, IDictionary properties) + public VelocityClientBase(string regionName, IDictionary properties) { region = regionName.GetHashCode().ToString(); //because the region name length is limited var cacheCluster = new CacheFactory(); From d843d40cb8af88f5e765ca0e70ba4d57da4b7db8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Delaporte?= <12201973+fredericdelaporte@users.noreply.github.com> Date: Tue, 27 Nov 2018 15:10:49 +0100 Subject: [PATCH 3/3] Remove unrelated change This change requires .Net Core 2.1 SDK --- .../NHibernate.Caches.CoreDistributedCache.Tests.csproj | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CoreDistributedCache/NHibernate.Caches.CoreDistributedCache.Tests/NHibernate.Caches.CoreDistributedCache.Tests.csproj b/CoreDistributedCache/NHibernate.Caches.CoreDistributedCache.Tests/NHibernate.Caches.CoreDistributedCache.Tests.csproj index 142e9329..fd88b603 100644 --- a/CoreDistributedCache/NHibernate.Caches.CoreDistributedCache.Tests/NHibernate.Caches.CoreDistributedCache.Tests.csproj +++ b/CoreDistributedCache/NHibernate.Caches.CoreDistributedCache.Tests/NHibernate.Caches.CoreDistributedCache.Tests.csproj @@ -30,4 +30,7 @@ + + +