Created
April 9, 2019 22:39
-
-
Save tugberkugurlu/4ada4b913cb12d3bd66857f4ac774dc6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From a20fc8e95ffd9bf5d424467e0e1283ae5891454a Mon Sep 17 00:00:00 2001 | |
From: Tugberk Ugurlu | |
Date: Tue, 9 Apr 2019 23:38:32 +0100 | |
Subject: [PATCH] add caching | |
--- | |
postsharp/0-caching/1-sample-web/1-sample-web.csproj | 1 + | |
postsharp/0-caching/1-sample-web/Program.cs | 3 +++ | |
postsharp/0-caching/1-sample-web/Startup.cs | 4 +++- | |
3 files changed, 7 insertions(+), 1 deletion(-) | |
diff --git a/postsharp/0-caching/1-sample-web/1-sample-web.csproj b/postsharp/0-caching/1-sample-web/1-sample-web.csproj | |
index bd55b6c..008c486 100644 | |
--- a/postsharp/0-caching/1-sample-web/1-sample-web.csproj | |
+++ b/postsharp/0-caching/1-sample-web/1-sample-web.csproj | |
@@ -10,6 +10,7 @@ | |
<PackageReference Include="Microsoft.AspNetCore.App" /> | |
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" /> | |
<PackageReference Include="PostSharp" Version="6.1.17" /> | |
+ <PackageReference Include="PostSharp.Patterns.Caching" Version="6.1.17" /> | |
<PackageReference Include="PostSharp.Patterns.Diagnostics" Version="6.1.17" /> | |
</ItemGroup> | |
diff --git a/postsharp/0-caching/1-sample-web/Program.cs b/postsharp/0-caching/1-sample-web/Program.cs | |
index 3dcae2c..9d241eb 100644 | |
--- a/postsharp/0-caching/1-sample-web/Program.cs | |
+++ b/postsharp/0-caching/1-sample-web/Program.cs | |
@@ -7,6 +7,8 @@ using Microsoft.AspNetCore; | |
using Microsoft.AspNetCore.Hosting; | |
using Microsoft.Extensions.Configuration; | |
using Microsoft.Extensions.Logging; | |
+using PostSharp.Patterns.Caching; | |
+using PostSharp.Patterns.Caching.Backends; | |
using PostSharp.Patterns.Diagnostics; | |
using PostSharp.Patterns.Diagnostics.Backends.Console; | |
@@ -18,6 +20,7 @@ namespace _1_sample_web | |
public static void Main(string[] args) | |
{ | |
LoggingServices.DefaultBackend = new ConsoleLoggingBackend(); | |
+ CachingServices.DefaultBackend = new MemoryCachingBackend(); | |
CreateWebHostBuilder(args).Build().Run(); | |
} | |
diff --git a/postsharp/0-caching/1-sample-web/Startup.cs b/postsharp/0-caching/1-sample-web/Startup.cs | |
index 18b3dbc..bed37ca 100644 | |
--- a/postsharp/0-caching/1-sample-web/Startup.cs | |
+++ b/postsharp/0-caching/1-sample-web/Startup.cs | |
@@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Hosting; | |
using Microsoft.AspNetCore.Http; | |
using Microsoft.AspNetCore.Mvc; | |
using Microsoft.Extensions.DependencyInjection; | |
+using PostSharp.Patterns.Caching; | |
namespace _1_sample_web | |
{ | |
@@ -115,7 +116,8 @@ namespace _1_sample_web | |
new KeyValuePair<int, Car>(7, new Car { Id = 7, Make = "Make7", Model = "Model5", Year = 2001, Price = 78355.92F }), | |
new KeyValuePair<int, Car>(8, new Car { Id = 8, Make = "Make8", Model = "Model1", Year = 2011, Price = 1823223.23F }) | |
}); | |
+ [Cache] | |
public IEnumerable<Car> GetAll() | |
{ | |
Thread.Sleep(500); | |
-- | |
2.15.2 (Apple Git-101.1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment