-
Notifications
You must be signed in to change notification settings - Fork 3
Caching
Examples of different caching strategies you can find in PubSubCache controller
Creating page that is composed of separate widgets can use caching in natural way. Each element can be cached at different levels separately.
Caching view models as whole view models with widget id and rendering action is rather pointless, especially because all view models are returned together from each service, in response to incoming request, so you will have to cache all returned view models. When you want to cache view model, it's probably when it depends on some parameters send in request - because you create view models in response to published request, getting data from it, or it renders some static content and doesn't depend on any parameter (when you want to cache element that not fully depends on parameters, so you accept stale results, you probably want to cache whole widget). In any case, instead of caching whole view model, you can create simple view model and order it to actually call action and not convert it into view name in view model expression tree while rendering view model. As a result given action will be called as child action, where you can pass parameters saved previously, and you can cache all child action as normal action.
Example of caching view model as child action:
[HttpGet]
[InternalAction]
public ActionResult CustomerSummary(Guid customerId)
{
var viewModel("widgetId", page => page.Html.Action("CustomerSummary", new ( id = customerId });
viewModel.InvokeAction = true;
// other actions
return ViewModels(viewModel);
}
[OutputCache]
[ServiceAction]
[ChildActionOnly]
public ActionResult CustomerSummary(Guid id)
{
//whole view model is cached
var customer = _databaase.Load<Customer>(id);
return View(customer);
}
Setting InvokeAction to true in ViewModel will prevent it from rendering view with given name and will actually call action method as specified while rendering view model. In this way we can cache chosen view models separately.
As child action results are cached on server side, we may want to cache widgets on client side. For doing so when we render view model that is responsible for wanted to cache widget, we only return some javascript code, that when page will be loaded will call service directly to get specific widget, or data needed for rendering it. In any case we can cache whole response, so in this way we can cache whole widget. We can also combine view model caching with widget caching:
[HttpGet]
[InternalAction]
public ActionResult CustomerSummary(Guid customerId)
{
var viewModel("widgetId", page => page.Html.Action("CustomerSummary", new ( id = customerId });
viewModel.InvokeAction = true;
// other actions
return ViewModels(viewModel);
}
[OutputCache]
[ServiceAction]
[ChildActionOnly]
public ActionResult CustomerSummary(Guid id)
{
//whole view model is cached
//we only return javascript code to make direct ajax call for widget
return View(id);
}
[OutputCache]
[ServiceAction]
public ActionResult CustomerWidget(Guid id)
{
//whole widget is cached
var customer = _databaase.Load<Customer>(id);
return View(customer);
}
Because we make ajax call directly to service action, and not via main app public api, we may cache its response in natural way.
You can always cache whole pages, or data responses as in every web application - for example if whole your page depends on some public data, you can include this data in main app action method parameter - even if you don't use it - so you will cache data according to this parameter as you planned.
Example of caching whole response data from main app:
[OutputCache]
public ActionResult CustomerSummary(Guid customerId, string publicValue)
{
//publicValue is not used but it allows to cache whole response according to this parameter
//handle request
}
-
Welcome
1.1 Project overview
1.2 Features -
Introduction
2.1 UI composition example
2.2 Service separation
2.3 Service communication
2.4 UI composition goals
2.5 Clues how to start
2.6 Potencial problems -
Identifying widgets
3.1 Naming widgets
3.2 Widgets format
3.3 Amount of widgets
3.4 Widgets and service boundaries
3.5 Widgets and caching
3.6 Grid for widgets -
Delivering view models
4.1 Publishing request
4.2 Internal routing
4.3 Data in view models
4.4 Gathering view models -
Rendering view models
5.1 External routing
5.2 Including route values
5.3 Finiding physical view files
5.4 Template views - Getting data from request
- Sharing resources
- Service api
-
Transactions
9.1 One transaction
9.2 Multiple transactions
9.3 Transaction performance - Dependency injection
- Public api changes
- [Tables] (https://github.com/padzikm/CompositeUI/wiki/Tables)
12.1 Table order
12.2 Server-side rendering
12.3 Client-side rendering
12.4 Nested tables -
Cross-service validation
13.1 Server-side validation
13.2 Client-side validation -
CRUD
14.1 Service private data
14.2 Create
14.3 Update
14.4 Delete
14.5 Preview -
Caching
15.1 View models
15.2 Widgets
15.3 Pages - Optimizing network calls
- Scalling
- Client-side communication
- Deployment
- Starting new project