Differences/Advantages of Cache vs Session

I have a Web Development question. What is the main difference between storing information in a Session v.s. a Cache? Advantages and disadvantages?
If I have a simple search page which returns the results to a data table and binds it to a grid view. If I want to store the search results, is it better to store it in a Session since each user would most likely have different results or can I still store the searches in Cache.

Jason from Washington DC

One thought on “Differences/Advantages of Cache vs Session

  1. Hi Jason
    One of the most important difference between the two is that items in the cache can expire (will be removed from cache) after a specified amount of time. Items put into a session will stay there, until the session ends.

    Secondly ASP.NET can also remove items from the cache when the amount of available memory gets small.

    Lastly the session state can be kept on an external (state server, SQL server) and shared between several instances of your web development application (for load balancing). This is cannot be done with a cache.

    Besides of these differences a session variable is per user/session while cache is per application.

Comments are closed.