diff --git a/src/EasyCaching.Core/CachingProviderType.cs b/src/EasyCaching.Core/CachingProviderType.cs new file mode 100644 index 00000000..d8e198c4 --- /dev/null +++ b/src/EasyCaching.Core/CachingProviderType.cs @@ -0,0 +1,15 @@ +namespace EasyCaching.Core +{ + /// + /// Caching provider type. + /// + public enum CachingProviderType + { + InMemory, + Memcached, + Redis, + SQLite, + Ext1, + Ext2 + } +} diff --git a/src/EasyCaching.Core/EasyCachingType.cs b/src/EasyCaching.Core/EasyCachingType.cs deleted file mode 100644 index 37a0d064..00000000 --- a/src/EasyCaching.Core/EasyCachingType.cs +++ /dev/null @@ -1,28 +0,0 @@ -namespace EasyCaching.Core -{ - /// - /// EasyCaching type. - /// - public enum EasyCachingType - { - /// - /// The Memory Cache (Local). - /// - Memory = 0, - - /// - /// The SQLite Cache (Local). - /// - SQLite = 1, - - /// - /// The Redis Cache (Remote). - /// - Redis = 2, - - /// - /// The Memcached (Remote). - /// - Memcached = 3, - } -} diff --git a/src/EasyCaching.Core/IEasyCachingProvider.cs b/src/EasyCaching.Core/IEasyCachingProvider.cs index bda63c7b..4e256fb8 100644 --- a/src/EasyCaching.Core/IEasyCachingProvider.cs +++ b/src/EasyCaching.Core/IEasyCachingProvider.cs @@ -224,6 +224,6 @@ public interface IEasyCachingProvider /// Gets the type of the caching provider. /// /// The type of the caching provider. - Internal.CachingProviderType CachingProviderType { get; } + CachingProviderType CachingProviderType { get; } } } diff --git a/src/EasyCaching.Core/Internal/BaseProviderOptions.cs b/src/EasyCaching.Core/Internal/BaseProviderOptions.cs index 5142da1b..b6b8352e 100644 --- a/src/EasyCaching.Core/Internal/BaseProviderOptions.cs +++ b/src/EasyCaching.Core/Internal/BaseProviderOptions.cs @@ -35,16 +35,5 @@ public class BaseProviderOptions public int Order { get; set; } } - /// - /// Caching provider type. - /// - public enum CachingProviderType - { - InMemory, - Memcached, - Redis, - SQLite, - Ext1, - Ext2 - } + } diff --git a/src/EasyCaching.Core/Internal/HybridCachingKeyType.cs b/src/EasyCaching.Core/Internal/HybridCachingKeyType.cs deleted file mode 100644 index 931c3c90..00000000 --- a/src/EasyCaching.Core/Internal/HybridCachingKeyType.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace EasyCaching.Core.Internal -{ - /// - /// Autofac key type. - /// - public class HybridCachingKeyType - { - /// - /// The local key. - /// - public const string LocalKey = "Local"; - - /// - /// The distributed key. - /// - public const string DistributedKey = "Distributed"; - } -} diff --git a/src/EasyCaching.HybridCache/HybridCachingProvider.cs b/src/EasyCaching.HybridCache/HybridCachingProvider.cs index ac150e71..4cc7a244 100644 --- a/src/EasyCaching.HybridCache/HybridCachingProvider.cs +++ b/src/EasyCaching.HybridCache/HybridCachingProvider.cs @@ -11,48 +11,60 @@ /// Hybrid caching provider. /// public class HybridCachingProvider : IHybridCachingProvider - { + { /// /// The caching providers. /// private readonly IEnumerable _providers; + /// + /// Gets a value indicating whether this is + /// distributed cache. + /// + /// true if is distributed cache; otherwise, false. + public bool IsDistributedCache => throw new NotImplementedException(); + + /// + /// Gets the order. + /// + /// The order. + public int Order => throw new NotImplementedException(); + + /// + /// Gets the max rd second. + /// + /// The max rd second. + public int MaxRdSecond => throw new NotImplementedException(); + + /// + /// Gets the type of the caching provider. + /// + /// The type of the caching provider. + public CachingProviderType CachingProviderType => throw new NotImplementedException(); + /// /// Initializes a new instance of the class. /// /// Providers. public HybridCachingProvider(IEnumerable providers) { - if(providers == null || !providers.Any()) + if (providers == null || !providers.Any()) { throw new ArgumentNullException(nameof(providers)); } //2-level and 3-level are enough for hybrid - if(providers.Count() > 3) + if (providers.Count() > 3) { - throw new ArgumentOutOfRangeException(nameof(providers)); + throw new ArgumentOutOfRangeException(nameof(providers)); } // - this._providers = providers.OrderBy(x=>x.Order); + this._providers = providers.OrderBy(x => x.Order); //TODO: local cache should subscribe the remote cache } - /// - /// Gets a value indicating whether this is - /// distributed cache. - /// - /// true if is distributed cache; otherwise, false. - public bool IsDistributedCache => true; - - public int Order => throw new NotImplementedException(); - - public int MaxRdSecond => throw new NotImplementedException(); - - public CachingProviderType CachingProviderType => throw new NotImplementedException(); - /// /// Exists the specified cacheKey. /// @@ -68,16 +80,16 @@ public bool Exists(string cacheKey) flag = local.Exists(cacheKey); - if(!flag) - { + if (!flag) + { //remote foreach (var provider in _providers.Skip(1)) { flag = provider.Exists(cacheKey); if (flag) break; - } - } + } + } return flag; } @@ -97,17 +109,17 @@ public async Task ExistsAsync(string cacheKey) flag = await local.ExistsAsync(cacheKey); - if (!flag) + if (!flag) { //remote foreach (var provider in _providers.Skip(1)) { flag = provider.Exists(cacheKey); - + if (flag) break; - } + } } - + return flag; } @@ -126,9 +138,9 @@ public CacheValue Get(string cacheKey, Func dataRetriever, TimeSpan exp var local = _providers.FirstOrDefault(); - CacheValue cachedValue = local.Get(cacheKey,dataRetriever,expiration); + CacheValue cachedValue = local.Get(cacheKey, dataRetriever, expiration); - if(cachedValue.HasValue) + if (cachedValue.HasValue) { return cachedValue; } @@ -282,7 +294,7 @@ public async Task> GetAsync(string cacheKey) where T : class return CacheValue.NoValue; } - return cachedValue; + return cachedValue; } /// @@ -347,7 +359,7 @@ public void Set(string cacheKey, T cacheValue, TimeSpan expiration) where T : foreach (var provider in _providers.Skip(1)) { provider.Set(cacheKey, cacheValue, expiration); - } + } } /// @@ -372,7 +384,7 @@ public async Task SetAsync(string cacheKey, T cacheValue, TimeSpan expiration foreach (var provider in _providers.Skip(1)) { provider.Set(cacheKey, cacheValue, expiration); - } + } } /// @@ -427,7 +439,7 @@ public void RemoveByPrefix(string prefix) foreach (var provider in _providers.Skip(1)) { provider.RemoveByPrefix(prefix); - } + } } /// @@ -447,7 +459,7 @@ public async Task RemoveByPrefixAsync(string prefix) foreach (var provider in _providers.Skip(1)) { provider.RemoveByPrefix(prefix); - } + } } /// @@ -469,7 +481,7 @@ public void SetAll(IDictionary values, TimeSpan expiration) where foreach (var provider in _providers.Skip(1)) { provider.SetAll(values, expiration); - } + } } /// @@ -492,7 +504,7 @@ public async Task SetAllAsync(IDictionary values, TimeSpan expirat foreach (var provider in _providers.Skip(1)) { provider.SetAll(values, expiration); - } + } } /// @@ -527,7 +539,7 @@ public IDictionary> GetAll(IEnumerable cacheKey localDict.Concat(disDict).ToDictionary(k => k.Key, v => v.Value); } - return localDict; + return localDict; } /// @@ -562,7 +574,7 @@ public async Task>> GetAllAsync(IEnumerable localDict.Concat(disDict).ToDictionary(k => k.Key, v => v.Value); } - return localDict; + return localDict; } /// @@ -586,7 +598,7 @@ public IDictionary> GetByPrefix(string prefix) where T { return localDict; } - + foreach (var item in localNotFindKeys) localDict.Remove(item); @@ -597,7 +609,7 @@ public IDictionary> GetByPrefix(string prefix) where T localDict.Concat(disDict).ToDictionary(k => k.Key, v => v.Value); } - return localDict; + return localDict; } /// @@ -641,12 +653,12 @@ public async Task>> GetByPrefixAsync(string /// Cache keys. public void RemoveAll(IEnumerable cacheKeys) { - ArgumentCheck.NotNullAndCountGTZero(cacheKeys, nameof(cacheKeys)); + ArgumentCheck.NotNullAndCountGTZero(cacheKeys, nameof(cacheKeys)); var local = _providers.FirstOrDefault(); local.RemoveAll(cacheKeys); - + //remote foreach (var provider in _providers.Skip(1)) { @@ -715,7 +727,7 @@ public async Task FlushAsync() tasks.Add(provider.FlushAsync()); } - await Task.WhenAll(tasks); + await Task.WhenAll(tasks); } } } diff --git a/src/EasyCaching.InMemory/InMemoryOptions.cs b/src/EasyCaching.InMemory/InMemoryOptions.cs index 9cb83bd1..9c17489f 100644 --- a/src/EasyCaching.InMemory/InMemoryOptions.cs +++ b/src/EasyCaching.InMemory/InMemoryOptions.cs @@ -1,5 +1,6 @@ namespace EasyCaching.InMemory { + using EasyCaching.Core; using EasyCaching.Core.Internal; public class InMemoryOptions : BaseProviderOptions diff --git a/src/EasyCaching.Memcached/MemcachedOptions.cs b/src/EasyCaching.Memcached/MemcachedOptions.cs index 6affd6f0..162ee484 100644 --- a/src/EasyCaching.Memcached/MemcachedOptions.cs +++ b/src/EasyCaching.Memcached/MemcachedOptions.cs @@ -1,5 +1,6 @@ namespace EasyCaching.Memcached { + using EasyCaching.Core; using EasyCaching.Core.Internal; public class MemcachedOptions : BaseProviderOptions diff --git a/src/EasyCaching.Redis/RedisOptions.cs b/src/EasyCaching.Redis/RedisOptions.cs index 37c275e0..71d38ef0 100644 --- a/src/EasyCaching.Redis/RedisOptions.cs +++ b/src/EasyCaching.Redis/RedisOptions.cs @@ -1,5 +1,6 @@ namespace EasyCaching.Redis { + using EasyCaching.Core; using EasyCaching.Core.Internal; public class RedisOptions: BaseProviderOptions diff --git a/src/EasyCaching.SQLite/SQLiteOptions.cs b/src/EasyCaching.SQLite/SQLiteOptions.cs index a1de2ea7..41057404 100644 --- a/src/EasyCaching.SQLite/SQLiteOptions.cs +++ b/src/EasyCaching.SQLite/SQLiteOptions.cs @@ -1,5 +1,6 @@ namespace EasyCaching.SQLite { + using EasyCaching.Core; using EasyCaching.Core.Internal; public class SQLiteOptions: BaseProviderOptions