3

I'm new to Service Stack, just discovered and looks very interesting to use.

I'd like my future websites to be quite backbone heavy but still ensure they can mostly be indexed by Google and seen by people with JavaScript (more for Google indexing)

I know there is content caching, such as lists etc which can be retrieved and severed the a razor page.

But I didn't see any methods of docs covering caching the entire razor page after being rendered, which is what I believe OutputCache attribute does on normal ASP.NET MVC 3.

So if anyone could direct me to possible examples of entire razor pages being cached using Service Stack, or a possible method of doing it would be greatly appreciated.

Thanks

Flo
  • 33
  • 1
  • 4

1 Answers1

1

Caching Razor/HTML views in ServiceStack is done in the same way as every other format by using ToOptimizedResultUsingCache e.g:

public object Any(CachedAllReqstars request)
{
    if (request.Aged <= 0)
        throw new ArgumentException("Invalid Age");

    var cacheKey = typeof(CachedAllReqstars).Name;
    return RequestContext.ToOptimizedResultUsingCache(Cache, cacheKey, () => 
        new ReqstarsResponse {
            Aged = request.Aged,
            Total = Db.GetScalar<int>("select count(*) from Reqstar"),
            Results = Db.Select<Reqstar>(q => q.Age == request.Aged)
        });
}

This service caches the output of any requested format, inc. HTML Razor Views.

mythz
  • 141,670
  • 29
  • 246
  • 390
  • Wow now that's a great feature, I didn't realise it includes HTML Razor Views. Just for further reading could you provide me the page which mentioned Razor Views included. But thanks again for the prompt answer. – Flo Feb 22 '13 at 15:54
  • What page? HTML is just another Content-Type in ServiceStack so works just like every other format, the difference is that you can further augment the HTML output by adding a Razor view with the same name as the Request or Response DTO, in this case `CachedAllReqstars.cshtml` or `ReqstarsResponse.cshtml` in the `/Views/` directory. – mythz Feb 22 '13 at 15:58