3

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

2 Answers 2

5

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.

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

3 Comments

Thanks. So can I use the Session object to store something like a user profile rather than querying the database each time?
Yes, the Session store can be reasonably guaranteed to represent the same user across requests.
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.
0

Use Session?

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

You could use caching on the controller I suppose.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.