Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
From f0889e68e55298e43360e01dd3b0e8b1cf6468e3 Mon Sep 17 00:00:00 2001
From: Tugberk Ugurlu
Date: Tue, 30 Apr 2019 09:40:21 +0100
Subject: [PATCH] cache invalidation, declarative
---
postsharp/0-caching/1-sample-web/Startup.cs | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/postsharp/0-caching/1-sample-web/Startup.cs b/postsharp/0-caching/1-sample-web/Startup.cs
index bed37ca..ec95d1e 100644
--- a/postsharp/0-caching/1-sample-web/Startup.cs
+++ b/postsharp/0-caching/1-sample-web/Startup.cs
@@ -62,7 +62,7 @@ namespace _1_sample_web
public IActionResult PutCar(int id, Car car)
{
car.Id = id;
- if (!_carsCtx.TryUpdate(car))
+ if (!_carsCtx.TryUpdate(id, car))
{
return NotFound();
}
@@ -130,6 +130,7 @@ namespace _1_sample_web
return _database.Values.Where(predicate);
}
+ [Cache]
public Tuple<bool, Car> GetSingle(int id)
{
Thread.Sleep(500);
@@ -166,7 +167,8 @@ namespace _1_sample_web
return _database.TryRemove(id, out removedCar);
}
- public bool TryUpdate(Car car)
+ [InvalidateCache(nameof(GetSingle))]
+ public bool TryUpdate(int id, Car car)
{
Thread.Sleep(500);
--
2.20.1 (Apple Git-117)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment