cache working
9313bf7043f121e2cd8010a2f40d98a75b5a847c
7 files changed
src/OpenKamer.LogicControllers/Web/Documenten.cssrc/OpenKamer.LogicControllers/Web/Doucumenten.cssrc/OpenKamer.LogicControllers/Web/MotiesCached.cssrc/OpenKamer.LogicControllers/Web/WebController.cssrc/OpenKamer.WebCore/Program.cssrc/OpenKamer.WebCore/wwwroot/Moties.htmsrc/OpenKamer.WebCore/wwwroot/Moties.js
diff --git a/src/OpenKamer.LogicControllers/Web/Doucumenten.cs b/src/OpenKamer.LogicControllers/Web/Documenten.cs
similarity index 100%
rename from src/OpenKamer.LogicControllers/Web/Doucumenten.cs
rename to src/OpenKamer.LogicControllers/Web/Documenten.cs
diff --git a/src/OpenKamer.LogicControllers/Web/MotiesCached.cs b/src/OpenKamer.LogicControllers/Web/MotiesCached.cs
new file mode 100644
index 0000000..19d97c1
--- /dev/null
+++ b/src/OpenKamer.LogicControllers/Web/MotiesCached.cs
@@ -0,0 +1,28 @@
+using Microsoft.AspNetCore.Mvc;
+
+using MongoDB.Driver;
+using MongoDB.MvcCore;
+
+namespace OpenKamer.LogicControllers.Web;
+
+public partial class WebController : ControllerBase
+{
+ [HttpPost]
+ [Route("~/api/MotiesCached")]
+ public async Task<IActionResult> MotiesCached()
+ {
+ // documentType
+ var pub = mongo.GetDatabase("public");
+
+ var a = @"[ { $skip: 0 }, { $limit: 100 } ]";
+
+ var List = await pub.GetCollection("list").Aggregate(a).ToListAsync();
+
+ return Ok(new
+ {
+ List
+ });
+ }
+
+
+}
diff --git a/src/OpenKamer.LogicControllers/Web/WebController.cs b/src/OpenKamer.LogicControllers/Web/WebController.cs
index 39b67d1..f3559be 100644
--- a/src/OpenKamer.LogicControllers/Web/WebController.cs
+++ b/src/OpenKamer.LogicControllers/Web/WebController.cs
@@ -7,9 +7,12 @@ namespace OpenKamer.LogicControllers.Web;
public partial class WebController : ControllerBase
{
+ private readonly IMongoClient mongo;
+
private readonly IMongoDatabase db;
- public WebController(IMongoDatabase db)
+ public WebController(IMongoClient mongo, IMongoDatabase db)
{
+ this.mongo = mongo;
this.db = db;
}
}
diff --git a/src/OpenKamer.WebCore/Program.cs b/src/OpenKamer.WebCore/Program.cs
index b094dae..3b512f2 100644
--- a/src/OpenKamer.WebCore/Program.cs
+++ b/src/OpenKamer.WebCore/Program.cs
@@ -26,7 +26,7 @@ var mongoSection = builder.Configuration.GetSection("Mongo");
var mongoclient = new MongoClient(mongoSection["ConnectionString"]);
-//builder.Services.AddSingleton<IMongoClient>(mongoclient);
+builder.Services.AddSingleton<IMongoClient>(mongoclient);
var db = mongoclient.GetDatabase(mongoSection["DbName"]);
diff --git a/src/OpenKamer.WebCore/wwwroot/Moties.htm b/src/OpenKamer.WebCore/wwwroot/Moties.htm
index c0ae1c5..3907f92 100644
--- a/src/OpenKamer.WebCore/wwwroot/Moties.htm
+++ b/src/OpenKamer.WebCore/wwwroot/Moties.htm
@@ -17,6 +17,8 @@
<body>
<img src="images/netproxyspinner.gif" id="netproxyspinner" />
+ <input type="checkbox" id="UseCache" />
+
<div id="Version"></div>
<div id="Output"></div>
diff --git a/src/OpenKamer.WebCore/wwwroot/Moties.js b/src/OpenKamer.WebCore/wwwroot/Moties.js
index 4b47a2a..a560ee3 100644
--- a/src/OpenKamer.WebCore/wwwroot/Moties.js
+++ b/src/OpenKamer.WebCore/wwwroot/Moties.js
@@ -17,6 +17,14 @@ function PageEvents()
if (typeof window[e.target.id] === "function")
window[e.target.id].call(e, e);
});
+
+ $id("UseCache").on("click", function (e)
+ {
+ if ($id("UseCache").checked)
+ MotiesCached();
+ else
+ Moties2();
+ });
}
function Init()
@@ -41,3 +49,11 @@ function Moties2()
Output.Template(TemplateMoties, this, false);
});
}
+
+function MotiesCached()
+{
+ netproxy("./api/MotiesCached", {}, function ()
+ {
+ Output.Template(TemplateMoties, this, false);
+ });
+}