Your controller classes only have a life cycle that extends from requesting action to rendering. Do you really need to cache this data? Just output the data to the model object. Queries do not seem complicated enough, and in addition, most RDBMS providers typically perform many caching queries.
HTTP is a stateless protocol, meaning that after a request, your web server forgets everything about this request. To get around this statelessness, asp.net offers application and session objects. The application is available worldwide for all requests, and Session is tied to a single IP address. Placing any data in it is usually the last resort, albeit a part of data caching schemes that do have a long download time.
The flow in ASP.NET MVC is approximately equal
- URL requested
- The controller is called
- Action called
- Action calls Model for data (username / user plan)
- Action sets data in view mode
- The action invokes the desired view with data in view mode.
- The view is displayed.
Setting the data on the viewmodel is already 'private', so I'm not sure where the caching comes from. Perhaps I do not understand the question?
Edit
Well, forgive me first if my post was a bit arrogant. I really think that your code should not even go into the constructor of your base constructor. In the end, you will not transfer your controller for viewing.
It is good practice to pass typed ViewModels. Say this is your definition in your .master site
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MyNS.BaseViewDataModel>" %>
And this is the definition of your help page:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MyNS.HelpViewDataModel>" %>
Then you can create a BaseViewDataModel
namespace MyNS { public class BaseViewDataModel
And your HelpViewDataModel
namespace MyNS { public class HelpViewDataModel : BaseViewDataModel {
Then, in your assistant, deal with the actions
[AcceptVerbs(HttpVerbs.Get)] public ActionResult Index() { var viewDataModel = new HelpViewDataModel (); viewDataModel.HelpText = "something"; .. .. return View(viewDataModel); }
Now you can create your custom pointer and user plan in the BaseViewDataModel constructor, and it will only be called for actions that actually create an instance of the BaseViewDataModel subclass.
And your views are safe in type, which is a huge increase in productivity, since we scored those views that we can now call
<%= this.Model.HelpText %>
In the help window.