Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Application vs Session vs Cache

Tags:

asp.net

What is an appropriate use case for all of the above? It seems session and cache are quite similar, and I can't think of much use for application.

like image 955
chobo Avatar asked Feb 23 '11 20:02

chobo


People also ask

What is the difference between session and application?

A session is usually for a user and only lasts from when they login to when they logout (or get timed out). Application State has a much longer lifetime, is shared between all users, and is only cleared when the process is restarted.

What is the difference between session cookies and cache?

The main difference between Cache and Cookie is that, Cache is used to store online page resources during a browser for the long run purpose or to decrease the loading time. On the other hand, cookies are employed to store user choices such as browsing session to trace the user preferences.

Can application session state be stored in cache?

SQL Server can also be used as a storage of session state. Custom session techniques are available on azure like table storage provider etc. The Cache is also stored on the server's memory, but it doesn't have a concern with the users. Any user within the same pool can access the application cache data.


2 Answers

Application and Session State have a very important difference:

Application state is a data repository available to all classes in an ASP.NET application. Application state is stored in memory on the server and is faster than storing and retrieving information in a database. Unlike session state, which is specific to a single user session, application state applies to all users and sessions. Therefore, application state is a useful place to store small amounts of often-used data that does not change from one user to another

Application State Overview
Session State Overview

Caching, on the other hand, allows you to store objects in memory that require extensive server resources to create - it offers powerful features that allow you to customize how items are cached and how long they are cached - you can set extensive properties like priority and expiration.

Caching Application Data Overview

Although they might appear similar, they are distinctly separate and have different roles to play in an ASP.NET application in its broadest sense.

like image 90
Ta01 Avatar answered Sep 21 '22 15:09

Ta01


Session is per user. It is not shared among users.

Application and Cache scope are application wide. Cache can be expired. If you have data that can be changed let's say 5 minutes, you can place that in cache, while if you have data that is not updated regularly, than it is the candidate of placing in application variable.

like image 28
Adeel Avatar answered Sep 20 '22 15:09

Adeel