Вопрос

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

Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top