1
votes

I have been searching high and low for this, but can't seem to find the right answer.

I have been writing a module in Orchard together with some widgets that I use for it, and now I want to enable caching of the database queries in my classes.

Is there any documentation on how to add caching to my modules and widgets?

I've tried to just enable the Output cache and the syscache, but it seems that it only works for the modules that came with Orchard (I checked with SQL Server Profiler, and my queries are still being sent all the time to the database, while the normal Orchard queries for content and such, are not, and seems to be cached).

1
You could implement Orchard built it Cache. More information weblogs.asp.net/bleroy/archive/2011/02/16/… and nogginbox.co.uk/blog/orchard-caching-by-timemberacochea

1 Answers

0
votes

You can use the ICacheManager.

Inject an instance of ICacheManager into your constructor and then in your method you can cache a value using:

var myCachedValue = _cacheManager.Get("My-Value-Cache-Key", ctx => {
    ctx.Monitor(_clock.When(TimeSpan.FromMinutes(20)));
    return SlowFunctionSoNeedsCaching();
});

I've written a more detailed example in my blog post: caching in Orchard.