1

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?

5
  • Cached in memory on server by default if you enable caching. Commented Jul 2, 2010 at 13:14
  • I know it's not on the client but is adding the gridview datasource to session state an option? Commented Jul 2, 2010 at 13:18
  • @johnc: You can add disconnected DTO's like DataTables to Session state. Be careful not to add "connected" objects like DataReaders, or you could maintain open database connections and overload the connection pool. Commented Jul 2, 2010 at 13:23
  • Yep, cant be done. A client doesnt know what a user control is. Just use intelligent partial caching on the user control (varybycustom - user.identity.name). Commented Jul 2, 2010 at 13:26
  • @RPM1984: Yup, thanks! That's what I did! Commented Jul 2, 2010 at 13:55

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

1 Comment

Thanks! I used a VaryByCustom directive to specify that the cache should only be available to the current user.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.