Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions build/releasenotes.props
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<Project>
<PropertyGroup>
<EasyCachingCorePackageNotes>
1. TrySet/TrySetAsync.
1. Improve Configuration.
</EasyCachingCorePackageNotes>
<EasyCachingMemcachedPackageNotes>
1. TrySet/TrySetAsync.
1. Improve Configuration.
</EasyCachingMemcachedPackageNotes>
<EasyCachingRedisPackageNotes>
1. TrySet/TrySetAsync.
1. Improve Configuration.
</EasyCachingRedisPackageNotes>
<EasyCachingSQLitePackageNotes>
1. TrySet/TrySetAsync.
1. Improve Configuration.
</EasyCachingSQLitePackageNotes>
<EasyCachingInMemoryPackageNotes>
1. Fix bug of TrySet/TrySetAsync.
1. Improve Configuration.
</EasyCachingInMemoryPackageNotes>
<EasyCachingHybridPackageNotes>
1. TrySet/TrySetAsync.
1. Improve Configuration.
</EasyCachingHybridPackageNotes>
<EasyCachingAspectCorePackageNotes>
1. Remove Dependency of IEasyCaching.
Expand All @@ -28,13 +28,13 @@
1. Support .NET Core 2.1
</EasyCachingResponseCachingPackageNotes>
<EasyCachingJsonPackageNotes>
1. Configurable JSON serializer
1. Improve Configuration.
</EasyCachingJsonPackageNotes>
<EasyCachingMessagePackPackageNotes>
1. Support .NET Core 2.1
1. Improve Configuration.
</EasyCachingMessagePackPackageNotes>
<EasyCachingProtobufPackageNotes>
1. Support .NET Core 2.1
1. Improve Configuration.
</EasyCachingProtobufPackageNotes>
</PropertyGroup>
</Project>
18 changes: 9 additions & 9 deletions build/version.props
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<Project>
<PropertyGroup>
<EasyCachingCorePackageVersion>0.4.2</EasyCachingCorePackageVersion>
<EasyCachingMemcachedPackageVersion>0.4.2</EasyCachingMemcachedPackageVersion>
<EasyCachingRedisPackageVersion>0.4.2</EasyCachingRedisPackageVersion>
<EasyCachingSQLitePackageVersion>0.4.2</EasyCachingSQLitePackageVersion>
<EasyCachingInMemoryPackageVersion>0.4.3</EasyCachingInMemoryPackageVersion>
<EasyCachingHybridPackageVersion>0.4.2</EasyCachingHybridPackageVersion>
<EasyCachingCorePackageVersion>0.4.5</EasyCachingCorePackageVersion>
<EasyCachingMemcachedPackageVersion>0.4.5</EasyCachingMemcachedPackageVersion>
<EasyCachingRedisPackageVersion>0.4.5</EasyCachingRedisPackageVersion>
<EasyCachingSQLitePackageVersion>0.4.5</EasyCachingSQLitePackageVersion>
<EasyCachingInMemoryPackageVersion>0.4.5</EasyCachingInMemoryPackageVersion>
<EasyCachingHybridPackageVersion>0.4.5</EasyCachingHybridPackageVersion>
<EasyCachingAspectCorePackageVersion>0.3.2</EasyCachingAspectCorePackageVersion>
<EasyCachingCastlePackageVersion>0.3.2</EasyCachingCastlePackageVersion>
<EasyCachingResponseCachingPackageVersion>0.3.0</EasyCachingResponseCachingPackageVersion>
<EasyCachingJsonPackageVersion>0.3.1</EasyCachingJsonPackageVersion>
<EasyCachingMessagePackPackageVersion>0.3.0</EasyCachingMessagePackPackageVersion>
<EasyCachingProtobufPackageVersion>0.3.0</EasyCachingProtobufPackageVersion>
<EasyCachingJsonPackageVersion>0.3.5</EasyCachingJsonPackageVersion>
<EasyCachingMessagePackPackageVersion>0.3.5</EasyCachingMessagePackPackageVersion>
<EasyCachingProtobufPackageVersion>0.3.5</EasyCachingProtobufPackageVersion>
</PropertyGroup>
</Project>
64 changes: 53 additions & 11 deletions sample/EasyCaching.Demo.Providers/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using EasyCaching.Memcached;
using EasyCaching.Redis;
using EasyCaching.SQLite;
using EasyCaching.Serialization.MessagePack;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
Expand All @@ -28,11 +29,50 @@ public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

//new configuration
services.AddEasyCaching(option=>
{
//use memory cache
option.UseInMemory("default");

//use memory cache
option.UseInMemory("cus");

//use redis cache
option.UseRedis(config =>
{
config.DBConfig.Endpoints.Add(new ServerEndPoint("127.0.0.1", 6379));
}, "redis1")
.WithMessagePack()//with messagepack serialization
;

//use redis cache
option.UseRedis(config =>
{
config.DBConfig.Endpoints.Add(new ServerEndPoint("127.0.0.1", 6380));
}, "redis2");

////use sqlite cache
//option.UseSQLite(config =>
//{
// config.DBConfig = new SQLiteDBOptions { FileName = "my.db" };
//});

////use memcached cached
//option.UseMemcached(config =>
//{
// config.DBConfig.AddServer("127.0.0.1", 11211);
//});

//option.UseMemcached(Configuration);

});

//1. Important step for using InMemory Cache
//services.AddDefaultInMemoryCache();

//services.AddDefaultInMemoryCacheWithFactory();
services.AddDefaultInMemoryCacheWithFactory("cus");
//services.AddDefaultInMemoryCacheWithFactory("cus");

//services.AddDefaultInMemoryCache(Configuration);

Expand All @@ -51,17 +91,17 @@ public void ConfigureServices(IServiceCollection services)
// option.DBConfig.Password = "";
//});

services.AddDefaultRedisCacheWithFactory("redis1",option =>
{
option.DBConfig.Endpoints.Add(new ServerEndPoint("127.0.0.1", 6379));
option.DBConfig.Password = "";
});
//services.AddDefaultRedisCacheWithFactory("redis1",option =>
//{
// option.DBConfig.Endpoints.Add(new ServerEndPoint("127.0.0.1", 6379));
// option.DBConfig.Password = "";
//});

services.AddDefaultRedisCacheWithFactory("redis2", option =>
{
option.DBConfig.Endpoints.Add(new ServerEndPoint("127.0.0.1", 6380));
option.DBConfig.Password = "";
});
//services.AddDefaultRedisCacheWithFactory("redis2", option =>
//{
// option.DBConfig.Endpoints.Add(new ServerEndPoint("127.0.0.1", 6380));
// option.DBConfig.Password = "";
//});

//services.AddDefaultRedisCache(Configuration);

Expand Down Expand Up @@ -105,6 +145,8 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
////4. Important step for using SQLite Cache
//app.UseSQLiteCache();

//app.UseEasyCaching();

app.UseMvc();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
namespace EasyCaching.Core
{
using Microsoft.AspNetCore.Builder;
using System;

public static class EasyCachingApplicationBuliderExtensions
{
/// <summary>
/// Uses the easy caching.
/// </summary>
/// <returns>The easy caching.</returns>
/// <param name="app">App.</param>
public static IApplicationBuilder UseEasyCaching(this IApplicationBuilder app)
{
if (app == null)
{
throw new ArgumentNullException(nameof(app));
}

var options = app.ApplicationServices.GetService(typeof(EasyCachingOptions));

if (options != null && options is EasyCachingOptions)
{
foreach (var serviceExtension in ((EasyCachingOptions)options).Extensions)
{
serviceExtension.WithServices(app);
}
}

return app;
}
}
}
35 changes: 35 additions & 0 deletions src/EasyCaching.Core/Configurations/EasyCachingOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
namespace EasyCaching.Core
{
using System.Collections.Generic;

/// <summary>
/// EasyCaching options.
/// </summary>
public class EasyCachingOptions
{
/// <summary>
/// Initializes a new instance of the <see cref="T:EasyCaching.Core.EasyCachingOptions"/> class.
/// </summary>
public EasyCachingOptions()
{
Extensions = new List<IEasyCachingOptionsExtension>();
}

/// <summary>
/// Gets the extensions.
/// </summary>
/// <value>The extensions.</value>
internal IList<IEasyCachingOptionsExtension> Extensions { get; }

/// <summary>
/// Registers the extension.
/// </summary>
/// <param name="extension">Extension.</param>
public void RegisterExtension(IEasyCachingOptionsExtension extension)
{
Internal.ArgumentCheck.NotNull(extension, nameof(extension));

Extensions.Add(extension);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
namespace EasyCaching.Core
{
using Microsoft.Extensions.DependencyInjection;
using System;

/// <summary>
/// EasyCaching service collection extensions.
/// </summary>
public static class EasyCachingServiceCollectionExtensions
{
/// <summary>
/// Adds the easycaching.
/// </summary>
/// <returns>The easy caching.</returns>
/// <param name="services">Services.</param>
/// <param name="setupAction">Setup action.</param>
public static IServiceCollection AddEasyCaching(this IServiceCollection services, Action<EasyCachingOptions> setupAction)
{
if (setupAction == null)
{
throw new ArgumentNullException(nameof(setupAction));
}

//Options and extension service
var options = new EasyCachingOptions();
setupAction(options);
foreach (var serviceExtension in options.Extensions)
{
serviceExtension.AddServices(services);
}
services.AddSingleton(options);

return services;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace EasyCaching.Core
{
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;

/// <summary>
/// EasyCaching options extension.
/// </summary>
public interface IEasyCachingOptionsExtension
{
/// <summary>
/// Adds the services.
/// </summary>
/// <param name="services">Services.</param>
void AddServices(IServiceCollection services);

/// <summary>
/// Withs the services.
/// </summary>
/// <param name="app">App.</param>
void WithServices(IApplicationBuilder app);
}
}
7 changes: 3 additions & 4 deletions src/EasyCaching.Core/EasyCaching.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@

<ItemGroup>
<Folder Include="Internal\" />
<Folder Include="Configurations\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.1.1" />
</ItemGroup>
<ItemGroup>
<Compile Remove="BaseEasyCachingProvider.cs" />
</ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.1.1" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion src/EasyCaching.Core/IEasyCachingProviderFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public IEasyCachingProvider GetCachingProvider(string name)
{
Internal.ArgumentCheck.NotNullOrWhiteSpace(name, nameof(name));

var provider = _cachingProviders.FirstOrDefault(x => x.Name.Equals(name));
var provider = _cachingProviders.FirstOrDefault(x => x.Name.Equals(name, System.StringComparison.OrdinalIgnoreCase));

if (provider == null) throw new System.ArgumentException("can not find a match caching provider!");

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace EasyCaching.HybridCache
{
using EasyCaching.Core;

/// <summary>
/// EasyCaching options extensions.
/// </summary>
public static class EasyCachingOptionsExtensions
{
/// <summary>
/// Uses the hybrid.
/// </summary>
/// <returns>The hybrid.</returns>
/// <param name="options">Options.</param>
public static EasyCachingOptions UseHybrid(this EasyCachingOptions options)
{
options.RegisterExtension(new HybridCacheOptionsExtension());

return options;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
namespace EasyCaching.HybridCache
{
using EasyCaching.Core;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;

/// <summary>
/// HybridCache options extension.
/// </summary>
internal sealed class HybridCacheOptionsExtension : IEasyCachingOptionsExtension
{
/// <summary>
/// Adds the services.
/// </summary>
/// <param name="services">Services.</param>
public void AddServices(IServiceCollection services)
{
services.TryAddSingleton<IHybridCachingProvider, HybridCachingProvider>();
}

/// <summary>
/// Withs the services.
/// </summary>
/// <param name="services">Services.</param>
public void WithServices(IApplicationBuilder services)
{
// Method intentionally left empty.
}
}
}
3 changes: 3 additions & 0 deletions src/EasyCaching.HybridCache/EasyCaching.HybridCache.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.1.1" />
</ItemGroup>
<ItemGroup>
<Folder Include="Configurations\" />
</ItemGroup>
</Project>
Loading