views:

34

answers:

2

Hi, I would like to know if it is possible to cache an ASP.NET UserControl on the Client.

I have an User Control that queries a DB and renders a GridView. It must be on the Client because the query results vary from user to user (by the User.Identity.Name). The page is for an intranet.

Any help would be really appreciated!

Thanks in advance,

PS: Where are the user controls cached by default? Server, Proxy?

+1  A: 

Proxy servers and clients can only cache static data. Dynamic data must always be served by IIS, though you can improve efficiency by storing data in an in-memory cache instead of querying a database for every request.

The term "caching", in regards to ASP.NET, most often refers to storing data in memory on the server. You serve different data to different users by using a key value, such as User.Identity.Name. If you want to cache a users' results on the server, you can add a DataSet (or other DTO) to the Cache dictionary using Cache.Add, using the user's ID as the key. If the data in question doesn't change very often, this can be an efficient way to serve user-specific data. If the data does change often, you can use the Cache object's callback mechanisms to expire cache items when (for example) a file changes.

IIS/ASP.NET also supports Page caching and partial caching of pages based on a querystring. These are controlled by page directives in the .aspx page, and per-site by the web.config.

Dave Swersky
A: 

User controls are ALWAYS cached on the web server, not on proxy servers or in web browsers.

To address your intent though, you can render different cached results based upon the VaryBy attributes of the OutputCache directive. These include:

  • VaryByParam
  • VaryByControl
  • VaryByCustom
alex
Thanks!I used a VaryByCustom directive to specify that the cache should only be available to the current user.
Joel Ferreras