diff --git a/src/EasyCaching.Core/EasyCaching.Core.csproj b/src/EasyCaching.Core/EasyCaching.Core.csproj index 4467317a..8503bda9 100644 --- a/src/EasyCaching.Core/EasyCaching.Core.csproj +++ b/src/EasyCaching.Core/EasyCaching.Core.csproj @@ -4,18 +4,18 @@ netstandard2.0 Catcher Wong Catcher Wong - 0.1.4 + 0.2.0 EasyCaching is a open source caching library that contains basic usages and some advanced usages of caching which can help us to handle caching more easier! Caching,Cache,Distributed,Memory,Interceptor,Synchronization,Hybrid - https://github.com/catcherwong/EasyCaching - https://github.com/catcherwong/EasyCaching/blob/master/LICENSE - https://github.com/catcherwong/EasyCaching - https://github.com/catcherwong/EasyCaching - https://raw.githubusercontent.com/catcherwong/EasyCaching/master/media/nuget-icon.png - - Add some new caching APIs. + https://github.com/dotnetcore/EasyCaching + https://github.com/dotnetcore/EasyCaching/blob/master/LICENSE + https://github.com/dotnetcore/EasyCaching + https://github.com/dotnetcore/EasyCaching + https://raw.githubusercontent.com/dotnetcore/EasyCaching/master/media/nuget-icon.png + + Add GetCount and Flush for providers. diff --git a/src/EasyCaching.Core/IEasyCachingProvider.cs b/src/EasyCaching.Core/IEasyCachingProvider.cs index 5cf43023..bf2f2241 100644 --- a/src/EasyCaching.Core/IEasyCachingProvider.cs +++ b/src/EasyCaching.Core/IEasyCachingProvider.cs @@ -189,5 +189,17 @@ public interface IEasyCachingProvider /// The all async. /// Cache keys. Task RemoveAllAsync(IEnumerable cacheKeys); + + /// + /// Gets the count. + /// + /// The count. + /// Prefix. + int GetCount(string prefix = ""); + + /// + /// Flush this instance. + /// + void Flush(); } } diff --git a/src/EasyCaching.Core/Internal/BaseRedisOptions.cs b/src/EasyCaching.Core/Internal/BaseRedisOptions.cs index 0b817daf..361a9b28 100644 --- a/src/EasyCaching.Core/Internal/BaseRedisOptions.cs +++ b/src/EasyCaching.Core/Internal/BaseRedisOptions.cs @@ -47,5 +47,12 @@ public class BaseRedisOptions /// The endpoints. /// public IList Endpoints { get; } = new List(); + + /// + /// Gets or sets a value indicating whether this + /// allow admin. + /// + /// true if allow admin; otherwise, false. + public bool AllowAdmin { get; set; } = false; } } diff --git a/src/EasyCaching.HybridCache/EasyCaching.HybridCache.csproj b/src/EasyCaching.HybridCache/EasyCaching.HybridCache.csproj index 01d68aba..b99ddce5 100644 --- a/src/EasyCaching.HybridCache/EasyCaching.HybridCache.csproj +++ b/src/EasyCaching.HybridCache/EasyCaching.HybridCache.csproj @@ -4,18 +4,18 @@ netstandard2.0 Catcher Wong Catcher Wong - 0.1.2 + 0.2.0 EasyCaching.HybridCache combines local caching and distributed caching. Caching,Cache,Synchronization,Hybrid - https://github.com/catcherwong/EasyCaching - https://github.com/catcherwong/EasyCaching/blob/master/LICENSE - https://github.com/catcherwong/EasyCaching - https://github.com/catcherwong/EasyCaching - https://raw.githubusercontent.com/catcherwong/EasyCaching/master/media/nuget-icon.png + https://github.com/dotnetcore/EasyCaching + https://github.com/dotnetcore/EasyCaching/blob/master/LICENSE + https://github.com/dotnetcore/EasyCaching + https://github.com/dotnetcore/EasyCaching + https://raw.githubusercontent.com/dotnetcore/EasyCaching/master/media/nuget-icon.png - Add some new caching APIs. + Implement GetCount and Flush. diff --git a/src/EasyCaching.HybridCache/HybridCachingProvider.cs b/src/EasyCaching.HybridCache/HybridCachingProvider.cs index 445cbd4e..6f9808fb 100644 --- a/src/EasyCaching.HybridCache/HybridCachingProvider.cs +++ b/src/EasyCaching.HybridCache/HybridCachingProvider.cs @@ -585,5 +585,32 @@ public async Task RemoveAllAsync(IEnumerable cacheKeys) System.Console.WriteLine(ex.Message); } } + + /// + /// Gets the count. + /// + /// The count. + /// Prefix. + public int GetCount(string prefix = "") + { + return Math.Max(_localCachingProvider.GetCount(prefix), _distributedCachingProvider.GetCount(prefix)); + } + + /// + /// Flush this instance. + /// + public void Flush() + { + _localCachingProvider.Flush(); + + try + { + _distributedCachingProvider.Flush(); + } + catch (Exception ex) + { + System.Console.WriteLine(ex.Message); + } + } } } diff --git a/src/EasyCaching.InMemory/DefaultInMemoryCachingProvider.cs b/src/EasyCaching.InMemory/DefaultInMemoryCachingProvider.cs index 7cfebeb7..7f6dedf7 100644 --- a/src/EasyCaching.InMemory/DefaultInMemoryCachingProvider.cs +++ b/src/EasyCaching.InMemory/DefaultInMemoryCachingProvider.cs @@ -455,5 +455,31 @@ public async Task RemoveAllAsync(IEnumerable cacheKeys) await Task.WhenAll(tasks); } + + /// + /// Gets the count. + /// + /// The count. + /// Prefix. + public int GetCount(string prefix = "") + { + return string.IsNullOrWhiteSpace(prefix) + ? _cacheKeys.Count + : _cacheKeys.Count(x => x.StartsWith(prefix.Trim(), StringComparison.OrdinalIgnoreCase)); + } + + /// + /// Flush this instance. + /// + public void Flush() + { + ////new instance + //_cache = new MemoryCache(new MemoryCacheOptions()); + + foreach (var item in _cacheKeys) + _cache.Remove(item); + + _cacheKeys.Clear(); + } } } diff --git a/src/EasyCaching.InMemory/EasyCaching.InMemory.csproj b/src/EasyCaching.InMemory/EasyCaching.InMemory.csproj index 3acff2ca..6b654166 100644 --- a/src/EasyCaching.InMemory/EasyCaching.InMemory.csproj +++ b/src/EasyCaching.InMemory/EasyCaching.InMemory.csproj @@ -4,18 +4,18 @@ netstandard2.0 Catcher Wong Catcher Wong - 0.1.4 + 0.2.0 In-memory cache based on EasyCaching.Core and Microsoft.Extensions.Caching.Memory Caching,Cache,In-Memory - https://github.com/catcherwong/EasyCaching - https://github.com/catcherwong/EasyCaching/blob/master/LICENSE - https://github.com/catcherwong/EasyCaching - https://github.com/catcherwong/EasyCaching - https://raw.githubusercontent.com/catcherwong/EasyCaching/master/media/nuget-icon.png + https://github.com/dotnetcore/EasyCaching + https://github.com/dotnetcore/EasyCaching/blob/master/LICENSE + https://github.com/dotnetcore/EasyCaching + https://github.com/dotnetcore/EasyCaching + https://raw.githubusercontent.com/dotnetcore/EasyCaching/master/media/nuget-icon.png - Add some new caching APIs. + Implement GetCount and Flush. diff --git a/src/EasyCaching.Interceptor.AspectCore/EasyCaching.Interceptor.AspectCore.csproj b/src/EasyCaching.Interceptor.AspectCore/EasyCaching.Interceptor.AspectCore.csproj index 0140d00a..8926bcd8 100644 --- a/src/EasyCaching.Interceptor.AspectCore/EasyCaching.Interceptor.AspectCore.csproj +++ b/src/EasyCaching.Interceptor.AspectCore/EasyCaching.Interceptor.AspectCore.csproj @@ -4,27 +4,18 @@ netstandard2.0 Catcher Wong Catcher Wong - 0.1.2 + 0.2.0 Caching Interceptor based on EasyCaching.Core and AspectCore Caching,Cache,Distributed,Memory,Interceptor,Synchronization - https://github.com/catcherwong/EasyCaching - https://github.com/catcherwong/EasyCaching/blob/master/LICENSE - https://github.com/catcherwong/EasyCaching - https://github.com/catcherwong/EasyCaching - https://raw.githubusercontent.com/catcherwong/EasyCaching/master/media/nuget-icon.png + https://github.com/dotnetcore/EasyCaching + https://github.com/dotnetcore/EasyCaching/blob/master/LICENSE + https://github.com/dotnetcore/EasyCaching + https://github.com/dotnetcore/EasyCaching + https://raw.githubusercontent.com/dotnetcore/EasyCaching/master/media/nuget-icon.png - v0.1.2 - 1. Enable IsAll when using Evict. - - v0.1.1 - 1. Get caching with data retriever => without data retriever . - 2. Caching Handle with async method. - 3. Introduct Able , Put And Evict. - - v0.1.0 - Init. + Add some extension methods. diff --git a/src/EasyCaching.Interceptor.Castle/EasyCaching.Interceptor.Castle.csproj b/src/EasyCaching.Interceptor.Castle/EasyCaching.Interceptor.Castle.csproj index 315cd562..3a8eaba2 100644 --- a/src/EasyCaching.Interceptor.Castle/EasyCaching.Interceptor.Castle.csproj +++ b/src/EasyCaching.Interceptor.Castle/EasyCaching.Interceptor.Castle.csproj @@ -4,26 +4,18 @@ netstandard2.0 Catcher Wong Catcher Wong - 0.1.2 + 0.2.0 Caching Interceptor based on EasyCaching.Core and Castle Caching,Cache,Distributed,Memory,Interceptor,Synchronization - https://github.com/catcherwong/EasyCaching - https://github.com/catcherwong/EasyCaching/blob/master/LICENSE - https://github.com/catcherwong/EasyCaching - https://github.com/catcherwong/EasyCaching - https://raw.githubusercontent.com/catcherwong/EasyCaching/master/media/nuget-icon.png + https://github.com/dotnetcore/EasyCaching + https://github.com/dotnetcore/EasyCaching/blob/master/LICENSE + https://github.com/dotnetcore/EasyCaching + https://github.com/dotnetcore/EasyCaching + https://raw.githubusercontent.com/dotnetcore/EasyCaching/master/media/nuget-icon.png - v0.1.2 - 1. Enable IsAll when using Evict. - - v0.1.1 - 1. Get caching with data retriever => without data retriever . - 2. Introduct Able , Put And Evict. - - v 0.1.0 - Init. + Add some extension methods. diff --git a/src/EasyCaching.Memcached/DefaultMemcachedCachingProvider.cs b/src/EasyCaching.Memcached/DefaultMemcachedCachingProvider.cs index 436ae2d4..0f7d6fae 100644 --- a/src/EasyCaching.Memcached/DefaultMemcachedCachingProvider.cs +++ b/src/EasyCaching.Memcached/DefaultMemcachedCachingProvider.cs @@ -460,5 +460,32 @@ public async Task RemoveAllAsync(IEnumerable cacheKeys) await Task.WhenAll(tasks); } + + /// + /// Gets the count. + /// + /// The count. + /// Prefix. + public int GetCount(string prefix = "") + { + if(string.IsNullOrWhiteSpace(prefix)) + { + //Inaccurate, sometimes, memcached just causes items to expire but not free up or flush memory at once. + return int.Parse(_memcachedClient.Stats().GetRaw("curr_items").FirstOrDefault().Value); + } + else + { + return 0; + } + } + + /// + /// Flush this instance. + /// + public void Flush() + { + //not flush memory at once, just causes all items to expire + _memcachedClient.FlushAll(); + } } } diff --git a/src/EasyCaching.Memcached/EasyCaching.Memcached.csproj b/src/EasyCaching.Memcached/EasyCaching.Memcached.csproj index 4ecec5ad..92db638b 100644 --- a/src/EasyCaching.Memcached/EasyCaching.Memcached.csproj +++ b/src/EasyCaching.Memcached/EasyCaching.Memcached.csproj @@ -4,18 +4,18 @@ netstandard2.0 Catcher Wong Catcher Wong - 0.1.5 + 0.2.0 EasyCaching.Memcached based on EasyCaching.Core and EnyimMemcachedCore Caching,Cache,Distributed,Memcached - https://github.com/catcherwong/EasyCaching - https://github.com/catcherwong/EasyCaching/blob/master/LICENSE - https://github.com/catcherwong/EasyCaching - https://github.com/catcherwong/EasyCaching - https://raw.githubusercontent.com/catcherwong/EasyCaching/master/media/nuget-icon.png + https://github.com/dotnetcore/EasyCaching + https://github.com/dotnetcore/EasyCaching/blob/master/LICENSE + https://github.com/dotnetcore/EasyCaching + https://github.com/dotnetcore/EasyCaching + https://raw.githubusercontent.com/dotnetcore/EasyCaching/master/media/nuget-icon.png - Simplify the usage of Memcached Transcoder + Implement GetCount and Flush. diff --git a/src/EasyCaching.Redis/DefaultRedisCachingProvider.cs b/src/EasyCaching.Redis/DefaultRedisCachingProvider.cs index 87d26665..c1d293c8 100644 --- a/src/EasyCaching.Redis/DefaultRedisCachingProvider.cs +++ b/src/EasyCaching.Redis/DefaultRedisCachingProvider.cs @@ -553,5 +553,36 @@ public async Task RemoveAllAsync(IEnumerable cacheKeys) if (redisKeys.Length > 0) await _cache.KeyDeleteAsync(redisKeys); } + + /// + /// Gets the count. + /// + /// The count. + /// Prefix. + public int GetCount(string prefix = "") + { + if(string.IsNullOrWhiteSpace(prefix)) + { + var allCount = 0; + + foreach (var server in _servers) + allCount += (int)server.DatabaseSize(_cache.Database); + + return allCount; + } + + return this.SearchRedisKeys(this.HandlePrefix(prefix)).Length; + } + + /// + /// Flush this instance. + /// + public void Flush() + { + foreach (var server in _servers) + { + server.FlushDatabase(_cache.Database); + } + } } } diff --git a/src/EasyCaching.Redis/EasyCaching.Redis.csproj b/src/EasyCaching.Redis/EasyCaching.Redis.csproj index 4bb826ec..b6f64daa 100644 --- a/src/EasyCaching.Redis/EasyCaching.Redis.csproj +++ b/src/EasyCaching.Redis/EasyCaching.Redis.csproj @@ -4,18 +4,18 @@ netstandard2.0 Catcher Wong Catcher Wong - 0.1.4 + 0.2.0 EasyCaching.Redis based on EasyCaching.Core and StackExchange.Redis Caching,Cache,Distributed,Redis - https://github.com/catcherwong/EasyCaching - https://github.com/catcherwong/EasyCaching/blob/master/LICENSE - https://github.com/catcherwong/EasyCaching - https://github.com/catcherwong/EasyCaching - https://raw.githubusercontent.com/catcherwong/EasyCaching/master/media/nuget-icon.png + https://github.com/dotnetcore/EasyCaching + https://github.com/dotnetcore/EasyCaching/blob/master/LICENSE + https://github.com/dotnetcore/EasyCaching + https://github.com/dotnetcore/EasyCaching + https://raw.githubusercontent.com/dotnetcore/EasyCaching/master/media/nuget-icon.png - Add some new caching APIs. + Implement GetCount and Flush. diff --git a/src/EasyCaching.Redis/RedisDatabaseProvider.cs b/src/EasyCaching.Redis/RedisDatabaseProvider.cs index 607dffbd..e9e3f74a 100644 --- a/src/EasyCaching.Redis/RedisDatabaseProvider.cs +++ b/src/EasyCaching.Redis/RedisDatabaseProvider.cs @@ -66,6 +66,7 @@ private ConnectionMultiplexer CreateConnectionMultiplexer() Password = _options.Password, Ssl = _options.IsSsl, SslHost = _options.SslHost, + AllowAdmin = _options.AllowAdmin }; foreach (var endpoint in _options.Endpoints) diff --git a/src/EasyCaching.SQLite/ConstSQL.cs b/src/EasyCaching.SQLite/ConstSQL.cs index 1736b6be..035ee888 100644 --- a/src/EasyCaching.SQLite/ConstSQL.cs +++ b/src/EasyCaching.SQLite/ConstSQL.cs @@ -57,6 +57,25 @@ FROM [easycaching] FROM [easycaching] WHERE [cachekey] = @cachekey AND [expiration] > strftime('%s','now')"; + /// + /// The countallsql. + /// + public const string COUNTALLSQL = @"SELECT COUNT(1) + FROM [easycaching] + WHERE [expiration] > strftime('%s','now')"; + + /// + /// The countprefixsql. + /// + public const string COUNTPREFIXSQL = @"SELECT COUNT(1) + FROM [easycaching] + WHERE [cachekey] like @cachekey AND [expiration] > strftime('%s','now')"; + + /// + /// The flushsql. + /// + public const string FLUSHSQL = @"DELETE FROM [easycaching]"; + /// /// The createsql. /// diff --git a/src/EasyCaching.SQLite/DefaultSQLiteCachingProvider.cs b/src/EasyCaching.SQLite/DefaultSQLiteCachingProvider.cs index ec7cac12..2db45688 100644 --- a/src/EasyCaching.SQLite/DefaultSQLiteCachingProvider.cs +++ b/src/EasyCaching.SQLite/DefaultSQLiteCachingProvider.cs @@ -506,5 +506,28 @@ public async Task RemoveAllAsync(IEnumerable cacheKeys) await Task.WhenAll(tasks); tran.Commit(); } + + /// + /// Gets the count. + /// + /// The count. + /// Prefix. + public int GetCount(string prefix = "") + { + if (string.IsNullOrWhiteSpace(prefix)) + { + return _cache.ExecuteScalar(ConstSQL.COUNTALLSQL); + } + else + { + return _cache.ExecuteScalar(ConstSQL.COUNTPREFIXSQL, new { cachekey = string.Concat(prefix, "%") }); + } + } + + /// + /// Flush this instance. + /// + public void Flush() => _cache.Execute(ConstSQL.FLUSHSQL); + } } diff --git a/src/EasyCaching.SQLite/EasyCaching.SQLite.csproj b/src/EasyCaching.SQLite/EasyCaching.SQLite.csproj index d2d1bf1e..9c35ecc6 100644 --- a/src/EasyCaching.SQLite/EasyCaching.SQLite.csproj +++ b/src/EasyCaching.SQLite/EasyCaching.SQLite.csproj @@ -4,18 +4,18 @@ netstandard2.0 Catcher Wong Catcher Wong - 0.1.4 + 0.2.0 EasyCaching.SQLite based on EasyCaching.Core and Microsoft.Data.SQLite Caching,Cache,SQLite - https://github.com/catcherwong/EasyCaching - https://github.com/catcherwong/EasyCaching/blob/master/LICENSE - https://github.com/catcherwong/EasyCaching - https://github.com/catcherwong/EasyCaching - https://raw.githubusercontent.com/catcherwong/EasyCaching/master/media/nuget-icon.png + https://github.com/dotnetcore/EasyCaching + https://github.com/dotnetcore/EasyCaching/blob/master/LICENSE + https://github.com/dotnetcore/EasyCaching + https://github.com/dotnetcore/EasyCaching + https://raw.githubusercontent.com/dotnetcore/EasyCaching/master/media/nuget-icon.png - Add some new caching APIs. + Implement GetCount and Flush. diff --git a/src/EasyCaching.Serialization.Json/EasyCaching.Serialization.Json.csproj b/src/EasyCaching.Serialization.Json/EasyCaching.Serialization.Json.csproj index 1bcc394d..31171790 100644 --- a/src/EasyCaching.Serialization.Json/EasyCaching.Serialization.Json.csproj +++ b/src/EasyCaching.Serialization.Json/EasyCaching.Serialization.Json.csproj @@ -9,11 +9,11 @@ EasyCaching.Serialization.Json based on EasyCaching.Core and Newtonsoft.Json. Caching,Serialization,Json - https://github.com/catcherwong/EasyCaching - https://github.com/catcherwong/EasyCaching/blob/master/LICENSE - https://github.com/catcherwong/EasyCaching - https://github.com/catcherwong/EasyCaching - https://raw.githubusercontent.com/catcherwong/EasyCaching/master/media/nuget-icon.png + https://github.com/dotnetcore/EasyCaching + https://github.com/dotnetcore/EasyCaching/blob/master/LICENSE + https://github.com/dotnetcore/EasyCaching + https://github.com/dotnetcore/EasyCaching + https://raw.githubusercontent.com/dotnetcore/EasyCaching/master/media/nuget-icon.png Init. diff --git a/src/EasyCaching.Serialization.MessagePack/EasyCaching.Serialization.MessagePack.csproj b/src/EasyCaching.Serialization.MessagePack/EasyCaching.Serialization.MessagePack.csproj index 84972d56..3a077128 100644 --- a/src/EasyCaching.Serialization.MessagePack/EasyCaching.Serialization.MessagePack.csproj +++ b/src/EasyCaching.Serialization.MessagePack/EasyCaching.Serialization.MessagePack.csproj @@ -9,11 +9,11 @@ EasyCaching.Serialization.MessagePack based on EasyCaching.Core and MessagePack. Caching,Serialization,MessagePack - https://github.com/catcherwong/EasyCaching - https://github.com/catcherwong/EasyCaching/blob/master/LICENSE - https://github.com/catcherwong/EasyCaching - https://github.com/catcherwong/EasyCaching - https://raw.githubusercontent.com/catcherwong/EasyCaching/master/media/nuget-icon.png + https://github.com/dotnetcore/EasyCaching + https://github.com/dotnetcore/EasyCaching/blob/master/LICENSE + https://github.com/dotnetcore/EasyCaching + https://github.com/dotnetcore/EasyCaching + https://raw.githubusercontent.com/dotnetcore/EasyCaching/master/media/nuget-icon.png Fix bug of AddDefaultMessagePackSerializer. diff --git a/src/EasyCaching.Serialization.Protobuf/EasyCaching.Serialization.Protobuf.csproj b/src/EasyCaching.Serialization.Protobuf/EasyCaching.Serialization.Protobuf.csproj index 0750908d..e04f7788 100644 --- a/src/EasyCaching.Serialization.Protobuf/EasyCaching.Serialization.Protobuf.csproj +++ b/src/EasyCaching.Serialization.Protobuf/EasyCaching.Serialization.Protobuf.csproj @@ -9,11 +9,11 @@ EasyCaching.Serialization.Protobuf based on EasyCaching.Core and protobuf-net. Caching,Serialization,Protobuf - https://github.com/catcherwong/EasyCaching - https://github.com/catcherwong/EasyCaching/blob/master/LICENSE - https://github.com/catcherwong/EasyCaching - https://github.com/catcherwong/EasyCaching - https://raw.githubusercontent.com/catcherwong/EasyCaching/master/media/nuget-icon.png + https://github.com/dotnetcore/EasyCaching + https://github.com/dotnetcore/EasyCaching/blob/master/LICENSE + https://github.com/dotnetcore/EasyCaching + https://github.com/dotnetcore/EasyCaching + https://raw.githubusercontent.com/dotnetcore/EasyCaching/master/media/nuget-icon.png Init. diff --git a/test/EasyCaching.UnitTests/CachingTests/BaseCachingProviderTest.cs b/test/EasyCaching.UnitTests/CachingTests/BaseCachingProviderTest.cs index 318967f5..2c14ce10 100644 --- a/test/EasyCaching.UnitTests/CachingTests/BaseCachingProviderTest.cs +++ b/test/EasyCaching.UnitTests/CachingTests/BaseCachingProviderTest.cs @@ -871,6 +871,58 @@ protected virtual async Task RemoveAllAsync_Should_Succeed() } #endregion + #region Flush + [Fact] + protected virtual void Flush_Should_Succeed() + { + for (var i = 0; i < 5; i++) + _provider.Set($"flush:{i}", $"value{i}", _defaultTs); + + for (var i = 0; i < 5; i++) + Assert.Equal($"value{i}", _provider.Get($"flush:{i}").Value); + + _provider.Flush(); + + for (var i = 0; i < 5; i++) + Assert.False(_provider.Get($"flush:{i}").HasValue); + } + #endregion + + #region GetCount + [Fact] + protected virtual void Get_Count_Without_Prefix_Should_Succeed() + { + _provider.Flush(); + var rd = Guid.NewGuid().ToString(); + + for (var i = 0; i < 5; i++) + _provider.Set($"{rd}:getcount:{i}", $"value{i}", _defaultTs); + + Assert.Equal(5, _provider.GetCount()); + + _provider.Remove($"{rd}:getcount:4"); + + Assert.Equal(4, _provider.GetCount()); + } + + [Fact] + protected virtual void Get_Count_With_Prefix_Should_Succeed() + { + _provider.Flush(); + var rd = Guid.NewGuid().ToString(); + + for (var i = 0; i < 5; i++) + _provider.Set($"{rd}:getcount:withprefix:{i}", $"value{i}", _defaultTs); + + Assert.Equal(5, _provider.GetCount($"{rd}:getcount:withprefix:")); + + _provider.Remove($"{rd}:getcount:withprefix:1"); + + Assert.Equal(4, _provider.GetCount($"{rd}:getcount:withprefix:")); + } + #endregion + + #region common method protected Dictionary GetMultiDict(string prefix = "") { diff --git a/test/EasyCaching.UnitTests/CachingTests/HybridCachingTest.cs b/test/EasyCaching.UnitTests/CachingTests/HybridCachingTest.cs index 4fea3abd..a358569c 100644 --- a/test/EasyCaching.UnitTests/CachingTests/HybridCachingTest.cs +++ b/test/EasyCaching.UnitTests/CachingTests/HybridCachingTest.cs @@ -19,6 +19,7 @@ public HybridCachingTest() { RedisCacheOptions options = new RedisCacheOptions() { + AllowAdmin = true, //Password = "" }; @@ -41,53 +42,17 @@ public HybridCachingTest() _defaultTs = TimeSpan.FromSeconds(30); } - //[Fact] - //protected override void SetAll_Should_Succeed() - //{ - - //} - - //[Fact] - //protected override async Task SetAllAsync_Should_Succeed() - //{ - // await Task.FromResult(1); - //} - - //[Fact] - //protected override void GetAll_Should_Succeed() - //{ - - //} - - //[Fact] - //protected override async Task GetAllAsync_Should_Succeed() - //{ - // await Task.FromResult(1); - //} - - //[Fact] - //protected override void GetByPrefix_Should_Succeed() - //{ - - //} - - //[Fact] - //protected override async Task GetByPrefixAsync_Should_Succeed() - //{ - // await Task.FromResult(1); - //} + [Fact] + protected override void Get_Count_Without_Prefix_Should_Succeed() + { - //[Fact] - //protected override void RemoveAll_Should_Succeed() - //{ + } - //} + [Fact] + protected override void Get_Count_With_Prefix_Should_Succeed() + { - //[Fact] - //protected override async Task RemoveAllAsync_Should_Succeed() - //{ - // await Task.FromResult(1); - //} + } } diff --git a/test/EasyCaching.UnitTests/CachingTests/MemcachedProviderTest.cs b/test/EasyCaching.UnitTests/CachingTests/MemcachedProviderTest.cs index cf95f208..42cb614a 100644 --- a/test/EasyCaching.UnitTests/CachingTests/MemcachedProviderTest.cs +++ b/test/EasyCaching.UnitTests/CachingTests/MemcachedProviderTest.cs @@ -125,6 +125,18 @@ protected override async Task GetByPrefixAsync_With_Not_Existed_Prefix_Should_Re } + [Fact] + protected override void Get_Count_Without_Prefix_Should_Succeed() + { + + } + + [Fact] + protected override void Get_Count_With_Prefix_Should_Succeed() + { + + } + private void SetCacheItem(string cacheKey, string cacheValue, string prefix) { var pre = _provider.Get(prefix); diff --git a/test/EasyCaching.UnitTests/CachingTests/RedisCachingProviderTest.cs b/test/EasyCaching.UnitTests/CachingTests/RedisCachingProviderTest.cs index 98298891..ddd8563b 100644 --- a/test/EasyCaching.UnitTests/CachingTests/RedisCachingProviderTest.cs +++ b/test/EasyCaching.UnitTests/CachingTests/RedisCachingProviderTest.cs @@ -15,6 +15,7 @@ public RedisCachingProviderTest() services.AddDefaultRedisCache(options => { options.Endpoints.Add(new ServerEndPoint("127.0.0.1", 6379)); + options.AllowAdmin = true; }); IServiceProvider serviceProvider = services.BuildServiceProvider(); _provider = serviceProvider.GetService(); @@ -24,7 +25,21 @@ public RedisCachingProviderTest() [Fact] public void Prefix_Equal_Asterisk_Should_Throw_ArgumentException() { - Assert.Throws(()=>_provider.RemoveByPrefix("*")); + Assert.Throws(() => _provider.RemoveByPrefix("*")); + } + + [Fact] + public void Fulsh_Should_Fail_When_AllowAdmin_Is_False() + { + IServiceCollection services = new ServiceCollection(); + services.AddDefaultRedisCache(options => + { + options.Endpoints.Add(new ServerEndPoint("127.0.0.1", 6379)); + }); + IServiceProvider serviceProvider = services.BuildServiceProvider(); + var provider = serviceProvider.GetService(); + + Assert.Throws(() => provider.Flush()); } @@ -36,7 +51,7 @@ public void Issues16_DateTimeTest() Dt = Convert.ToDateTime("2018-02-12 12:11:00") }; - _provider.Set("activity",model,_defaultTs); + _provider.Set("activity", model, _defaultTs); var res = _provider.Get("activity");