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) ?
Fragment caching does not actually cache a Web Form's code fragments directly; fragment caching refers to the caching of individual user controls (. ascx) within a Web Form. Each user control can have independent cache durations and implementations of how the caching behavior is to be applied.
Fragment Caching (Partial Page Caching) - Inside ASP.NET [Book]
Any (Default)- Content is cached in three locations- the Web Server, any proxy Servers and the Web Browser. Client- Content is cached on the Web Browser. Server- Content is cached on the Web Server. ServerAndClient- Content is cached on the Web Server and the Web Browser.
To create a partial view, right click on the Shared folder -> click Add -> click View.. to open the Add View popup, as shown below. You can create a partial view in any View folder. However, it is recommended to create all your partial views in the Shared folder so that they can be used in multiple views.
Phil Haack wrote a short blog post on a similar topic called Donut Hole Caching. It serve as a good starting point.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With