Reputation: 11266
I have the following situation on a webapp:
A table "Employees" contains column "Department" and "Function". Both are dropdownlists.
The "Function" dropdownlist options depend on the selected "department". (so each department has its own list of functions)
When changing the department, I do an ajax call to a controller action with parameter "DepartmentId". Theres an [outputcache] attribute on the controlleraction so the functions that it returns get cached for every department ID.
My problem is the initial loading of the page. Can you call a controlleraction in a view and take advantage of the caching?
Anyone? 30 views and no answers.. Any remarks about my question? Too obvious? too hard? too weird? something for google (altho I didn't find a solution there) ?
Upvotes: 5
Views: 7282
Reputation: 15984
I would use subcontrollers or better still partial requests to do what you are asking. In a typical page I tend to not cache the whole page but instead break up areas into different action methods which are called via partial requests. That way I can have output caching on each area with differing expirations. It's more page life-cycles but when they are cached they really are not a tax on performance. It's also far easier to maintain and optimize a specific area if it starts to under perform.
In my experience this also fits very nicely with ajax patterns as you only every "get" your data from one action method.
Partial requests are discussed here and subcontrollers here
Hope this helps.
Upvotes: 4
Reputation: 82
Phil Haack wrote a short blog post on a similar topic called Donut Hole Caching. It serve as a good starting point.
Upvotes: 4
Reputation: 4807
Do you mean that you want to call the controller action that generates the functions directly while generating the view and not with ajax? If I understood that correctly, I don't think it's possible to get at the data in the output cache (I may be wrong though). Anyway, if you could get it, you'd still have to decode the data again.
You could also try to
Upvotes: 0