17 June, 2013

Nice little cache library for Nancy

Built a little NancyFX app for a customer where multiple browsers now are pulling the Nancy web app. This tunnels trough to the backend (which is not a regular database) and generates a little too much traffic for IT to be happy.

For a long term solution to this I’m leaning towards SignalR but I haven’t quite wrapped my head around it yet. So for a shorter term low effort fix I want to put in some caching in the Nancy-layer. After Googling around a bit I found Nancy.LightningCahce. Looks like a nice syntax with a AsCacheable extension method:

Get["/builds/progress"] = _ => {
IList<IBuildInProgress> builds = serviceAgent.GetBuildsInProgress();
return Response.AsJson(builds).AsCacheable(DateTime.Now.AddSeconds(10)) ;
view raw gistfile1.cs hosted with ❤ by GitHub

When adding Nancy.LightningCache to the solution and adding writing the code according to the Readme everything compiled fine but I got an exception runtime:


  • [MissingMethodException: Method not found: ‘Nancy.Routing.ResolveReslut Nancy.Routing IRouteResolver.Rresolve(Nancy.NancyContext)] <- For searchability*

After digging a bit I remembered their last commit message on github: “updated to Nancy 0.17.1”. What version did I have? 0.16.0. So I updated to 0.17.1 and lo and behold; Bob is your uncle!

Tags: ,