views:

487

answers:

2

Since there is no concept of sessions in ASP.Net MVC and each request is independent of each other would I ever make use of the Cache object to internally cache data in order to minimize db access? The output caching functionality is great for caching view data but if I wanted to cache something like a user profile which should be shared amongst requests from the same user what would I do?

Thanks

A: 

Use Session?

Session is per user's session Cache is sitewide for everyone

You could use caching on the controller I suppose.

rball
+3  A: 

There is certainly the concept of a session in MVC... Session data is persisted across requests. I think you may be confusing that with ViewState, which is persisted across postbacks to the same page and isn't applicable in MVC.

Rex M
Thanks. So can I use the Session object to store something like a user profile rather than querying the database each time?
NabilS
Yes, the Session store can be reasonably guaranteed to represent the same user across requests.
Rex M
And yes, you can store objects in it like a cache. It lives in the web tier memory by default, unless you use a SessionProvider that points to SQL or another state server.
Rex M