Skip to content

Commit

Permalink
Merge pull request #327 from dotnetcore/dev
Browse files Browse the repository at this point in the history
v1.4.1
  • Loading branch information
catcherwong authored Oct 7, 2021
2 parents 159a930 + d93f7ba commit c842bfe
Show file tree
Hide file tree
Showing 22 changed files with 221 additions and 54 deletions.
13 changes: 7 additions & 6 deletions build/releasenotes.props
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
<Project>
<PropertyGroup>
<EasyCachingCorePackageNotes>
1. Support distributed lock.
1. Expose raw cache database.
</EasyCachingCorePackageNotes>
<EasyCachingMemcachedPackageNotes>
1. Support distributed lock.
1. Expose raw cache database.
</EasyCachingMemcachedPackageNotes>
<EasyCachingRedisPackageNotes>
1. Support distributed lock.
1. Expose raw cache database.
2. Support KeyPrefix.
</EasyCachingRedisPackageNotes>
<EasyCachingSQLitePackageNotes>
1. Upgrading dependencies.
1. Expose raw cache database.
</EasyCachingSQLitePackageNotes>
<EasyCachingInMemoryPackageNotes>
1. Upgrading dependencies.
1. Expose raw cache database.
</EasyCachingInMemoryPackageNotes>
<EasyCachingHybridPackageNotes>
1. Upgrading dependencies.
Expand Down Expand Up @@ -52,7 +53,7 @@
1. Upgrading dependencies.
</EasyCachingDiskPackageNotes>
<EasyCachingLiteDBPackageNotes>
1. Upgrading dependencies.
1. Expose raw cache database.
</EasyCachingLiteDBPackageNotes>
<EasyCachingSTJsonPackageNotes>
1. Upgrading dependencies.
Expand Down
40 changes: 20 additions & 20 deletions build/version.props
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
<Project>
<PropertyGroup>
<EasyCachingCorePackageVersion>1.4.0</EasyCachingCorePackageVersion>
<EasyCachingMemcachedPackageVersion>1.4.0</EasyCachingMemcachedPackageVersion>
<EasyCachingRedisPackageVersion>1.4.0</EasyCachingRedisPackageVersion>
<EasyCachingSQLitePackageVersion>1.4.0</EasyCachingSQLitePackageVersion>
<EasyCachingInMemoryPackageVersion>1.4.0</EasyCachingInMemoryPackageVersion>
<EasyCachingHybridPackageVersion>1.4.0</EasyCachingHybridPackageVersion>
<EasyCachingAspectCorePackageVersion>1.4.0</EasyCachingAspectCorePackageVersion>
<EasyCachingCastlePackageVersion>1.4.0</EasyCachingCastlePackageVersion>
<EasyCachingResponseCachingPackageVersion>1.4.0</EasyCachingResponseCachingPackageVersion>
<EasyCachingJsonPackageVersion>1.4.0</EasyCachingJsonPackageVersion>
<EasyCachingMessagePackPackageVersion>1.4.0</EasyCachingMessagePackPackageVersion>
<EasyCachingProtobufPackageVersion>1.4.0</EasyCachingProtobufPackageVersion>
<EasyCachingCSRedisPackageVersion>1.4.0</EasyCachingCSRedisPackageVersion>
<EasyCachingRedisBusPackageVersion>1.4.0</EasyCachingRedisBusPackageVersion>
<EasyCachingCSRedisBusPackageVersion>1.4.0</EasyCachingCSRedisBusPackageVersion>
<EasyCachingRabbitBusPackageVersion>1.4.0</EasyCachingRabbitBusPackageVersion>
<EasyCachingDiskPackageVersion>1.4.0</EasyCachingDiskPackageVersion>
<EasyCachingMsExtPackageVersion>1.4.0</EasyCachingMsExtPackageVersion>
<EasyCachingLiteDBPackageVersion>1.4.0</EasyCachingLiteDBPackageVersion>
<EasyCachingSTJsonPackageVersion>1.4.0</EasyCachingSTJsonPackageVersion>
<EasyCachingCorePackageVersion>1.4.1</EasyCachingCorePackageVersion>
<EasyCachingMemcachedPackageVersion>1.4.1</EasyCachingMemcachedPackageVersion>
<EasyCachingRedisPackageVersion>1.4.1</EasyCachingRedisPackageVersion>
<EasyCachingSQLitePackageVersion>1.4.1</EasyCachingSQLitePackageVersion>
<EasyCachingInMemoryPackageVersion>1.4.1</EasyCachingInMemoryPackageVersion>
<EasyCachingHybridPackageVersion>1.4.1</EasyCachingHybridPackageVersion>
<EasyCachingAspectCorePackageVersion>1.4.1</EasyCachingAspectCorePackageVersion>
<EasyCachingCastlePackageVersion>1.4.1</EasyCachingCastlePackageVersion>
<EasyCachingResponseCachingPackageVersion>1.4.1</EasyCachingResponseCachingPackageVersion>
<EasyCachingJsonPackageVersion>1.4.1</EasyCachingJsonPackageVersion>
<EasyCachingMessagePackPackageVersion>1.4.1</EasyCachingMessagePackPackageVersion>
<EasyCachingProtobufPackageVersion>1.4.1</EasyCachingProtobufPackageVersion>
<EasyCachingCSRedisPackageVersion>1.4.1</EasyCachingCSRedisPackageVersion>
<EasyCachingRedisBusPackageVersion>1.4.1</EasyCachingRedisBusPackageVersion>
<EasyCachingCSRedisBusPackageVersion>1.4.1</EasyCachingCSRedisBusPackageVersion>
<EasyCachingRabbitBusPackageVersion>1.4.1</EasyCachingRabbitBusPackageVersion>
<EasyCachingDiskPackageVersion>1.4.1</EasyCachingDiskPackageVersion>
<EasyCachingMsExtPackageVersion>1.4.1</EasyCachingMsExtPackageVersion>
<EasyCachingLiteDBPackageVersion>1.4.1</EasyCachingLiteDBPackageVersion>
<EasyCachingSTJsonPackageVersion>1.4.1</EasyCachingSTJsonPackageVersion>
</PropertyGroup>
</Project>
9 changes: 4 additions & 5 deletions src/EasyCaching.CSRedis/DefaultCSRedisCachingProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using EasyCaching.Core;
using EasyCaching.Core.DistributedLock;
using EasyCaching.Core.Serialization;
using EasyCaching.CSRedis.DistributedLock;
using EasyCaching.CSRedis.DistributedLock;
using global::CSRedis;
using Microsoft.Extensions.Logging;
using System;
Expand Down Expand Up @@ -482,9 +482,8 @@ public override TimeSpan BaseGetExpiration(string cacheKey)
/// Get te information of this provider.
/// </summary>
/// <returns></returns>
public override ProviderInfo BaseGetProviderInfo()
{
return _info;
}
public override ProviderInfo BaseGetProviderInfo() => _info;

public override object BaseGetDatabse() => _cache;
}
}
3 changes: 3 additions & 0 deletions src/EasyCaching.Core/EasyCachingAbstractProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public abstract class EasyCachingAbstractProvider : IEasyCachingProvider
public CachingProviderType CachingProviderType => this.ProviderType;
public CacheStats CacheStats => this.ProviderStats;

public object Database => BaseGetDatabse();

protected EasyCachingAbstractProvider() { }

protected EasyCachingAbstractProvider(IDistributedLockFactory lockFactory, BaseProviderOptions options)
Expand All @@ -39,6 +41,7 @@ protected EasyCachingAbstractProvider(IDistributedLockFactory lockFactory, BaseP
_options = options;
}

public abstract object BaseGetDatabse();
public abstract bool BaseExists(string cacheKey);
public abstract Task<bool> BaseExistsAsync(string cacheKey);
public abstract void BaseFlush();
Expand Down
5 changes: 5 additions & 0 deletions src/EasyCaching.Core/IEasyCachingProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,10 @@ public interface IEasyCachingProvider : IEasyCachingProviderBase
/// </summary>
/// <returns></returns>
ProviderInfo GetProviderInfo();

/// <summary>
/// Get or sets the provider's database
/// </summary>
object Database { get; }
}
}
7 changes: 3 additions & 4 deletions src/EasyCaching.Disk/DefaultDiskCachingProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -673,9 +673,8 @@ private void DeleteDirectory(string path)
}
}

public override ProviderInfo BaseGetProviderInfo()
{
return _info;
}
public override ProviderInfo BaseGetProviderInfo() => _info;

public override object BaseGetDatabse() => throw new Exception("Disk provider don't support this ");
}
}
7 changes: 3 additions & 4 deletions src/EasyCaching.InMemory/DefaultInMemoryCachingProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,8 @@ public override TimeSpan BaseGetExpiration(string cacheKey)
/// Get te information of this provider.
/// </summary>
/// <returns></returns>
public override ProviderInfo BaseGetProviderInfo()
{
return _info;
}
public override ProviderInfo BaseGetProviderInfo() => _info;

public override object BaseGetDatabse() => _cache;
}
}
7 changes: 3 additions & 4 deletions src/EasyCaching.LiteDB/DefaultLiteDBCachingProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,8 @@ public override TimeSpan BaseGetExpiration(string cacheKey)
/// Get te information of this provider.
/// </summary>
/// <returns></returns>
public override ProviderInfo BaseGetProviderInfo()
{
return _info;
}
public override ProviderInfo BaseGetProviderInfo() => _info;

public override object BaseGetDatabse() => _cache;
}
}
2 changes: 2 additions & 0 deletions src/EasyCaching.Memcached/DefaultMemcachedCachingProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@ public override ProviderInfo BaseGetProviderInfo()
return _info;
}

public override object BaseGetDatabse() => _memcachedClient;

private void OnCacheHit(string cacheKey)
{
CacheStats.OnHit();
Expand Down
5 changes: 5 additions & 0 deletions src/EasyCaching.Redis/Configurations/RedisDBOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,10 @@ public class RedisDBOptions : BaseRedisOptions
/// Specifies the time in milliseconds that the system should allow for synchronous operations (defaults to 5 seconds)
/// </summary>
public int SyncTimeout { get; set; }

/// <summary>
/// Gets or sets the Redis database KeyPrefix will use.
/// </summary>
public string KeyPrefix { get; set; }
}
}
9 changes: 7 additions & 2 deletions src/EasyCaching.Redis/Configurations/RedisDatabaseProvider.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace EasyCaching.Redis
{
using StackExchange.Redis;
using StackExchange.Redis.KeyspaceIsolation;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -20,7 +21,7 @@ public class RedisDatabaseProvider : IRedisDatabaseProvider
/// The connection multiplexer.
/// </summary>
private Lazy<ConnectionMultiplexer> _connectionMultiplexer;

public RedisDatabaseProvider(string name, RedisOptions options)
{
_options = options.DBConfig;
Expand All @@ -39,7 +40,11 @@ public IDatabase GetDatabase()
{
try
{
return _connectionMultiplexer.Value.GetDatabase();

var database = _connectionMultiplexer.Value.GetDatabase();
if (!string.IsNullOrEmpty(_options.KeyPrefix))
database = database.WithKeyPrefix(_options.KeyPrefix);
return database;
}
catch (Exception)
{
Expand Down
7 changes: 3 additions & 4 deletions src/EasyCaching.Redis/DefaultRedisCachingProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,8 @@ public override TimeSpan BaseGetExpiration(string cacheKey)
/// Get te information of this provider.
/// </summary>
/// <returns></returns>
public override ProviderInfo BaseGetProviderInfo()
{
return _info;
}
public override ProviderInfo BaseGetProviderInfo() => _info;

public override object BaseGetDatabse() => _cache;
}
}
7 changes: 3 additions & 4 deletions src/EasyCaching.SQLite/DefaultSQLiteCachingProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -413,9 +413,8 @@ public override TimeSpan BaseGetExpiration(string cacheKey)
/// Get te information of this provider.
/// </summary>
/// <returns></returns>
public override ProviderInfo BaseGetProviderInfo()
{
return _info;
}
public override ProviderInfo BaseGetProviderInfo() => _info;

public override object BaseGetDatabse() => _cache;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@ protected override IEasyCachingProvider CreateCachingProvider(Action<BaseProvide
IServiceProvider serviceProvider = services.BuildServiceProvider();
return serviceProvider.GetService<IEasyCachingProvider>();
}

[Fact]
public void GetDatabase_Should_Succeed()
{
var db = _provider.Database;

Assert.NotNull(db);
Assert.IsType<EasyCachingCSRedisClient>(db);
}

[Fact]
public void GetDatabase_And_Use_Raw_Method_Should_Succeed()
{
var db = (EasyCachingCSRedisClient)_provider.Database;
var flag = db.Ping();
Assert.True(flag);
}
}

public class CSRedisCachingProviderWithNamedSerTest
Expand Down
16 changes: 16 additions & 0 deletions test/EasyCaching.UnitTests/CachingTests/HybridCachingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,22 @@ public async Task Distributed_Set_Async_Throw_Exception_Should_Not_Break()
Assert.Equal(default(string), res.Value);
}

[Fact]
public void Iss_311_Test()
{
var cacheKey = $"{_namespace}_iss311_{Guid.NewGuid()}";

hybridCaching_1.Set(cacheKey, "val", TimeSpan.FromSeconds(30));

var afterSet = hybridCaching_1.Exists(cacheKey);
Assert.True(afterSet);

hybridCaching_1.Remove(cacheKey);

var afterRemove = hybridCaching_1.Exists(cacheKey);
Assert.False(afterRemove);
}

private void FakeCreatProvider()
{
A.CallTo(() => fakeFactory.GetCachingProvider("m1")).Returns(new FakeLocalCachingProvider());
Expand Down
10 changes: 10 additions & 0 deletions test/EasyCaching.UnitTests/CachingTests/LiteDBCachingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.IO;
using System.Threading.Tasks;
using Xunit;
using global::LiteDB;

public class LiteDBCachingTest : BaseCachingProviderTest
{
Expand Down Expand Up @@ -45,6 +46,15 @@ protected override Task GetAsync_Parallel_Should_Succeed()
protected override void Get_Parallel_Should_Succeed()
{
}

[Fact]
public void GetDatabase_Should_Succeed()
{
var db = _provider.Database;

Assert.NotNull(db);
Assert.IsAssignableFrom<ILiteCollection<CacheItem>>(db);
}
}


Expand Down
18 changes: 17 additions & 1 deletion test/EasyCaching.UnitTests/CachingTests/MemcachedProviderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,24 @@ private void GetCacheItem(string cacheKey, string prefix)
var val = _provider.Get<string>(cacheKey);
Assert.False(val.HasValue);
}
}

[Fact]
public void GetDatabase_Should_Succeed()
{
var db = _provider.Database;

Assert.NotNull(db);
Assert.IsType<EasyCachingMemcachedClient>(db);
}

[Fact]
public void GetDatabase_And_Use_Raw_Method_Should_Succeed()
{
var db = (EasyCachingMemcachedClient)_provider.Database;
var stats = db.Stats();
Assert.NotNull(stats);
}
}

public class MemcachedProviderWithFactoryTest : BaseCachingProviderWithFactoryTest
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,17 @@ public void Issues150_DeepClone_Object_Test()

Assert.Equal("catcherwong", res2.Value.Name);
}

[Fact]
public void GetDatabase_Should_Succeed()
{
var db = _provider.Database;

Assert.NotNull(db);
Assert.IsType<InMemoryCaching>(db);
}
}

public class MemoryCachingProviderWithFactoryTest : BaseCachingProviderWithFactoryTest
{
public MemoryCachingProviderWithFactoryTest()
Expand Down
Loading

0 comments on commit c842bfe

Please sign in to comment.