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/Async/CoreDistributedCache.cs b/CoreDistributedCache/NHibernate.Caches.CoreDistributedCache/Async/CoreDistributedCache.cs index 5b0411cf..39ed8a3c 100644 --- a/CoreDistributedCache/NHibernate.Caches.CoreDistributedCache/Async/CoreDistributedCache.cs +++ b/CoreDistributedCache/NHibernate.Caches.CoreDistributedCache/Async/CoreDistributedCache.cs @@ -13,19 +13,20 @@ 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 : ICache + + public abstract partial class CoreDistributedCacheBase : 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 +50,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 +94,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 +118,7 @@ public Task RemoveAsync(object key, CancellationToken cancellationToken) } /// - public Task ClearAsync(CancellationToken cancellationToken) + public override Task ClearAsync(CancellationToken cancellationToken) { if (cancellationToken.IsCancellationRequested) { @@ -135,7 +136,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 +144,7 @@ public Task LockAsync(object key, CancellationToken cancellationToken) } try { - Lock(key); - return Task.CompletedTask; + return Task.FromResult(Lock(key)); } catch (Exception ex) { @@ -153,7 +153,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 +161,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..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 : ICache + 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 : ICache /// /// 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) @@ -83,7 +182,7 @@ public CoreDistributedCache( } /// - public string RegionName { get; } + public override string RegionName { get; } /// /// The expiration delay applied to cached items. @@ -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 @@ -239,7 +338,7 @@ private string GetCacheKey(object key) } /// - public object Get(object key) + public override object Get(object key) { if (key == null) { @@ -262,7 +361,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 +394,7 @@ public void Put(object key, object value) } /// - public void Remove(object key) + public override void Remove(object key) { if (key == null) { @@ -308,7 +407,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 +415,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..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 @@ -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..a3609cc5 100644 --- a/CoreMemoryCache/NHibernate.Caches.CoreMemoryCache/CoreMemoryCache.cs +++ b/CoreMemoryCache/NHibernate.Caches.CoreMemoryCache/CoreMemoryCache.cs @@ -24,22 +24,137 @@ 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. /// /// /// 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 : 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 partial class CoreMemoryCache : ICache 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,14 +216,14 @@ 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); } /// - public string RegionName { get; } + public override string RegionName { get; } /// /// The expiration delay applied to cached items. @@ -197,7 +312,7 @@ private object GetCacheKey(object key) } /// - public object Get(object key) + public override object Get(object key) { if (key == null) { @@ -211,7 +326,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 +359,7 @@ public void Put(object key, object value) } /// - public void Remove(object key) + public override void Remove(object key) { if (key == null) { @@ -257,7 +372,7 @@ public void Remove(object key) } /// - public void Clear() + public override void Clear() { _clearTokenLock.EnterWriteLock(); try @@ -273,7 +388,7 @@ public void Clear() } /// - public void Destroy() + public override void Destroy() { Clear(); _clearTokenLock.Dispose(); @@ -281,24 +396,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..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 partial class MemCacheClient : ICache + 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 partial class MemCacheClient : ICache 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; @@ -92,10 +205,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 +232,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 +255,7 @@ public void Put(object key, object value) } /// - public void Remove(object key) + public override void Remove(object key) { if (key == null) { @@ -153,43 +266,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; } } @@ -207,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/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..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 partial class MemCacheClient : ICache + 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 partial class MemCacheClient : ICache 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 }; @@ -125,10 +225,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 +255,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 +276,7 @@ public void Put(object key, object value) } /// - public void Remove(object key) + public override void Remove(object key) { if (key == null) { @@ -191,43 +291,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; } } @@ -235,7 +336,7 @@ public 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/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..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 partial class PrevalenceCache : ICache + 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,29 +117,29 @@ public partial class PrevalenceCache : ICache /// /// 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(); } - #region ICache Members + #region CacheBase Members /// - public object Get(object key) + public override object Get(object key) { if (key == null) { @@ -67,7 +167,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 +185,7 @@ public void Put(object key, object value) } /// - public void Remove(object key) + public override void Remove(object key) { if (key == null) { @@ -98,45 +198,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..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 partial class RtMemoryCache : ICache + 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 partial class RtMemoryCache : ICache /// /// 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; @@ -183,7 +293,7 @@ private string GetCacheKey(object key) } /// - public object Get(object key) + public override object Get(object key) { if (key == null) { @@ -203,7 +313,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 +347,7 @@ public void Put(object key, object value) } /// - public void Remove(object key) + public override void Remove(object key) { if (key == null) { @@ -249,7 +359,7 @@ public void Remove(object key) } /// - public void Clear() + public override void Clear() { RemoveRootCacheKey(); StoreRootCacheKey(); @@ -289,33 +399,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..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 partial class SharedCacheClient : ICache + 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; @@ -67,7 +167,7 @@ public SharedCacheClient(string regionName, IDictionary properti } /// - public object Get(object key) + public override object Get(object key) { if (key == null) { @@ -79,7 +179,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 +196,7 @@ public void Put(object key, object value) } /// - public void Remove(object key) + public override void Remove(object key) { if (key == null) { @@ -108,37 +208,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..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 partial class SysCache : ICache + 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 partial class SysCache : ICache /// /// 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; @@ -242,7 +357,7 @@ private string GetCacheKey(object key) } /// - public object Get(object key) + public override object Get(object key) { if (key == null) { @@ -262,7 +377,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 +412,7 @@ public void Put(object key, object value) } /// - public void Remove(object key) + public override void Remove(object key) { if (key == null) { @@ -309,7 +424,7 @@ public void Remove(object key) } /// - public void Clear() + public override void Clear() { RemoveRootCacheKey(); StoreRootCacheKey(); @@ -347,33 +462,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..422b802b 100644 --- a/SysCache2/NHibernate.Caches.SysCache2.Tests/SysCacheProviderFixture.cs +++ b/SysCache2/NHibernate.Caches.SysCache2.Tests/SysCacheProviderFixture.cs @@ -48,15 +48,15 @@ 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"); } 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/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..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 partial class SysCacheRegion : ICache + 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 partial class SysCacheRegion : ICache /// 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)) @@ -94,10 +198,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 +211,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 +241,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 +312,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 +331,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 } @@ -484,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/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..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 partial class VelocityClient : ICache + 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(); @@ -86,10 +186,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 +202,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 +219,7 @@ public void Put(object key, object value) } /// - public void Remove(object key) + public override void Remove(object key) { if (key == null) { @@ -134,19 +234,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 +257,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 +276,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) {