Skip to content

Commit

Permalink
🚧 Caching Interceptor.
Browse files Browse the repository at this point in the history
  • Loading branch information
catcherwong committed Jan 14, 2018
1 parent 267b120 commit 8206e26
Show file tree
Hide file tree
Showing 24 changed files with 562 additions and 117 deletions.
28 changes: 21 additions & 7 deletions EasyCaching.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EasyCaching.Core", "src\Eas
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EasyCaching.InMemory", "src\EasyCaching.InMemory\EasyCaching.InMemory.csproj", "{B9490432-737B-4518-B851-9D40FD29B392}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EasyCaching.Demo.Interceptor", "sample\EasyCaching.Demo.Interceptor\EasyCaching.Demo.Interceptor.csproj", "{C94E91EB-1F55-40E7-9A69-BBFEF740839C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EasyCaching.SQLite", "src\EasyCaching.SQLite\EasyCaching.SQLite.csproj", "{09FCF125-522E-4C0F-9CF0-0377A3F2A1A0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EasyCaching.Redis", "src\EasyCaching.Redis\EasyCaching.Redis.csproj", "{7F72FA56-C4E8-4EF5-963D-FC4174453574}"
Expand All @@ -37,6 +35,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EasyCaching.Sync.RabbitMQ",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EasyCaching.Demo.SQLite", "sample\EasyCaching.Demo.SQLite\EasyCaching.Demo.SQLite.csproj", "{9DD08645-38D0-4EB8-8127-347512B1DF4C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EasyCaching.Interceptor.Castle", "src\EasyCaching.Interceptor.Castle\EasyCaching.Interceptor.Castle.csproj", "{7B55B6D9-4221-4E82-AED6-BEC9A60C99D2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EasyCaching.Demo.Interceptor.Castle", "sample\EasyCaching.Demo.Interceptor.Castle\EasyCaching.Demo.Interceptor.Castle.csproj", "{C343BF4C-F025-4DB6-8A9B-DE8B12DCCAAE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EasyCaching.Demo.Interceptor.AspectCore", "sample\EasyCaching.Demo.Interceptor.AspectCore\EasyCaching.Demo.Interceptor.AspectCore.csproj", "{36D12667-E5C2-4C91-A450-A070DE07A3E6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -51,10 +55,6 @@ Global
{B9490432-737B-4518-B851-9D40FD29B392}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B9490432-737B-4518-B851-9D40FD29B392}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B9490432-737B-4518-B851-9D40FD29B392}.Release|Any CPU.Build.0 = Release|Any CPU
{C94E91EB-1F55-40E7-9A69-BBFEF740839C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C94E91EB-1F55-40E7-9A69-BBFEF740839C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C94E91EB-1F55-40E7-9A69-BBFEF740839C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C94E91EB-1F55-40E7-9A69-BBFEF740839C}.Release|Any CPU.Build.0 = Release|Any CPU
{09FCF125-522E-4C0F-9CF0-0377A3F2A1A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{09FCF125-522E-4C0F-9CF0-0377A3F2A1A0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{09FCF125-522E-4C0F-9CF0-0377A3F2A1A0}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -103,11 +103,22 @@ Global
{9DD08645-38D0-4EB8-8127-347512B1DF4C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9DD08645-38D0-4EB8-8127-347512B1DF4C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9DD08645-38D0-4EB8-8127-347512B1DF4C}.Release|Any CPU.Build.0 = Release|Any CPU
{7B55B6D9-4221-4E82-AED6-BEC9A60C99D2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7B55B6D9-4221-4E82-AED6-BEC9A60C99D2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7B55B6D9-4221-4E82-AED6-BEC9A60C99D2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7B55B6D9-4221-4E82-AED6-BEC9A60C99D2}.Release|Any CPU.Build.0 = Release|Any CPU
{C343BF4C-F025-4DB6-8A9B-DE8B12DCCAAE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C343BF4C-F025-4DB6-8A9B-DE8B12DCCAAE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C343BF4C-F025-4DB6-8A9B-DE8B12DCCAAE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C343BF4C-F025-4DB6-8A9B-DE8B12DCCAAE}.Release|Any CPU.Build.0 = Release|Any CPU
{36D12667-E5C2-4C91-A450-A070DE07A3E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{36D12667-E5C2-4C91-A450-A070DE07A3E6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{36D12667-E5C2-4C91-A450-A070DE07A3E6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{36D12667-E5C2-4C91-A450-A070DE07A3E6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{CE61FAA2-0233-451C-991D-4222ED61C84B} = {A0F5CC7E-155F-4726-8DEB-E966950B3FE9}
{B9490432-737B-4518-B851-9D40FD29B392} = {A0F5CC7E-155F-4726-8DEB-E966950B3FE9}
{C94E91EB-1F55-40E7-9A69-BBFEF740839C} = {F88D727A-9F9C-43D9-90B1-D4A02BF8BC98}
{09FCF125-522E-4C0F-9CF0-0377A3F2A1A0} = {A0F5CC7E-155F-4726-8DEB-E966950B3FE9}
{7F72FA56-C4E8-4EF5-963D-FC4174453574} = {A0F5CC7E-155F-4726-8DEB-E966950B3FE9}
{D5626647-1E42-4584-BC42-354D8BD94FE7} = {A0F5CC7E-155F-4726-8DEB-E966950B3FE9}
Expand All @@ -120,5 +131,8 @@ Global
{07326A03-B144-469F-837B-31DD3E0EB1AC} = {A0F5CC7E-155F-4726-8DEB-E966950B3FE9}
{265FB0C5-2C34-438D-B671-63836954EB5A} = {A0F5CC7E-155F-4726-8DEB-E966950B3FE9}
{9DD08645-38D0-4EB8-8127-347512B1DF4C} = {F88D727A-9F9C-43D9-90B1-D4A02BF8BC98}
{7B55B6D9-4221-4E82-AED6-BEC9A60C99D2} = {A0F5CC7E-155F-4726-8DEB-E966950B3FE9}
{C343BF4C-F025-4DB6-8A9B-DE8B12DCCAAE} = {F88D727A-9F9C-43D9-90B1-D4A02BF8BC98}
{36D12667-E5C2-4C91-A450-A070DE07A3E6} = {F88D727A-9F9C-43D9-90B1-D4A02BF8BC98}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
namespace EasyCaching.Demo.Interceptor.Controllers
{
using EasyCaching.Demo.Interceptor.Services;
using Microsoft.AspNetCore.Mvc;

[Route("api/[controller]")]
public class ValuesController : Controller
{
private readonly IDateTimeService _service;

public ValuesController(IDateTimeService service)
{
this._service = service;
namespace EasyCaching.Demo.Interceptor.AspectCore.Controllers
{
using EasyCaching.Demo.Interceptor.AspectCore.Services;
using Microsoft.AspNetCore.Mvc;

[Route("api/[controller]")]
public class ValuesController : Controller
{
private readonly IDateTimeService _service;

public ValuesController(IDateTimeService service)
{
this._service = service;
}

[HttpGet]
public string Get()
{
return _service.GetCurrentUtcTime();
}
}
}

[HttpGet]
public string Get()
{
return _service.GetCurrentUtcTime();
}
}
}
19 changes: 19 additions & 0 deletions sample/EasyCaching.Demo.Interceptor.AspectCore/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace EasyCaching.Demo.Interceptor.AspectCore
{
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;

public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}

public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseUrls("http://localhost:55555")
.Build();
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
namespace EasyCaching.Demo.Interceptor.Services
namespace EasyCaching.Demo.Interceptor.AspectCore.Services
{
using EasyCaching.Core.Internal;

public interface IDateTimeService : EasyCaching.Core.Internal.IEasyCaching
{
[EasyCaching.Interceptor.AspectCore.DefaultEasyCachingInterceptor(AbsoluteExpiration = 10)]
[EasyCachingInterceptor(Expiration = 10)]
string GetCurrentUtcTime();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
namespace EasyCaching.Demo.Interceptor
namespace EasyCaching.Demo.Interceptor.AspectCore
{
using System;
using EasyCaching.Demo.Interceptor.Services;
using EasyCaching.InMemory;
using EasyCaching.Interceptor.AspectCore;
using System;
using EasyCaching.Demo.Interceptor.AspectCore.Services;
using EasyCaching.InMemory;
using EasyCaching.Interceptor.AspectCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }

public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddMvc();

services.AddScoped<IDateTimeService,DateTimeService>();
using Microsoft.Extensions.DependencyInjection;

public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }

public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddScoped<IDateTimeService, DateTimeService>();

services.AddDefaultInMemoryCache();

return services.ConfigureAspectCoreInterceptor();
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

app.UseMvc();
}
}
}

services.AddMvc();

return services.ConfigureAspectCoreInterceptor();
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

app.UseMvc();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace EasyCaching.Demo.Interceptor.Castle.Controllers
{
[Route("api/[controller]")]
public class ValuesController : Controller
{
private readonly IDateTimeService _service;

public ValuesController(IDateTimeService service)
{
this._service = service;
}

[HttpGet]
public string Get()
{
return _service.GetCurrentUtcTime();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Folder Include="Services\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
</ItemGroup>

<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\EasyCaching.Core\EasyCaching.Core.csproj" />
<ProjectReference Include="..\..\src\EasyCaching.Interceptor.Castle\EasyCaching.Interceptor.Castle.csproj" />
<ProjectReference Include="..\..\src\EasyCaching.InMemory\EasyCaching.InMemory.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace EasyCaching.Demo.Interceptor
namespace EasyCaching.Demo.Interceptor.Castle
{
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace EasyCaching.Demo.Interceptor.Castle
{
using EasyCaching.Core.Internal;

public interface IDateTimeService
{
string GetCurrentUtcTime();
}

public class DateTimeService : IDateTimeService , IEasyCaching
{
[EasyCachingInterceptor(Expiration = 10)]
public string GetCurrentUtcTime()
{
return System.DateTime.UtcNow.ToString();
}
}
}
41 changes: 41 additions & 0 deletions sample/EasyCaching.Demo.Interceptor.Castle/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
namespace EasyCaching.Demo.Interceptor.Castle
{
using EasyCaching.InMemory;
using EasyCaching.Interceptor.Castle;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;

public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }

public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddMvc();

services.AddTransient<IDateTimeService,DateTimeService>();

services.AddDefaultInMemoryCache();

return services.ConfigureCastleInterceptor();
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

app.UseMvc();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
15 changes: 15 additions & 0 deletions sample/EasyCaching.Demo.Interceptor.Castle/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"Logging": {
"IncludeScopes": false,
"Debug": {
"LogLevel": {
"Default": "Warning"
}
},
"Console": {
"LogLevel": {
"Default": "Warning"
}
}
}
}
23 changes: 23 additions & 0 deletions src/EasyCaching.Core/Internal/EasyCachingInterceptorAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace EasyCaching.Core.Internal
{
using System;

/// <summary>
/// Easycaching interceptor attribute.
/// </summary>
[AttributeUsage(AttributeTargets.Method, Inherited = true)]
public class EasyCachingInterceptorAttribute : Attribute
{
/// <summary>
/// Gets or sets the expiration.
/// </summary>
/// <value>The expiration.</value>
public int Expiration { get; set; } = 30;

/// <summary>
/// Gets or sets the parameter count.
/// </summary>
/// <value>The parameter count.</value>
public int ParamCount { get; set; } = 5;
}
}
Loading

0 comments on commit 8206e26

Please sign in to comment.