Storages: Session, Local, Angular and Redis

Storages: Session, Local, Angular and Redis

      Comments Off on Storages: Session, Local, Angular and Redis

What is Session Storage

The read-only Session Storage is a property. It accesses a session storage object because of the current origin. It is very similar to localstorage. The difference that they have is that the data in localstorage doesn’t expire. Whereas the data in session storage is cleared. This happens whenever the page session has ended.

The difference: The Local Storage and the Session Storage

Web storage objects, both, local storage and session storage are designed to allow saving data in the browser. An interesting fact about them is that the data survives even after a page gets refreshedduring the sessionstorage. It happens for local storage when even a full browser restarts.

Their Utilisation

Cookies are already there. Then what is the need for additional objects? There are multiple reasons why these web storages are imperative. Some of them are discussed below.

  • Security Issue: The data is saved locally. It can’t be only read by the server. This reduces the security issue inthose cookies that are present. Everything’s done in JavaScript in this.
  • Higher Data Savings: For most browsers 10Mb is the limit for saving data. However these allow much more data to be saved.
  • Accessing Data: Bound to the origin, domain or protocol it port triplet, the storage can’t access data from each other. Different protocols or sub-domains infer different storage objects.

Local Storage

Local storage has certain principal features:

Same origin of data: Data which is shared between all windows as well as tabs are from the same origin.

No expiration of data: The data has noexpiration date. Even after the browser restarts, it will remain intact. It also survives OS reboot.

Work with Strings exclusively: It only works when the ‘key’ and ‘value’- both values are strings. Specifications of any other type, for example a number, or even an object, will automaticallyconvertsinto string.

How to use session storage in ASP.Net Core | InfoWorld

It can be accessed like anobject:

In this case, plain object way of getting or setting keys can also be used. This is alloweddue to historical reasons, and it works in mostcases.

Still it is not recommended. Some of the reasons for it are:

In case the key is generated by user, it can be anything.Like, it can be length or toString, or any another builtin method of localstorage. For instance like these get Item or set Item works fine.

Looping Over Keys

Key functionality as amethod offer get or set or removes options. However retaining all saved values or keys is possible. But storage objects cannot be iterated. The key in localstorage loop can be used like any other regular objects.

Session Storage

SessionStorage object has much lessutilisation than localstorage. Even though methods and properties are the same, the functionality is far more limited in comparison. The existence of the session storage tab is only limited within the current browser. A different tab with the same page will possess another session storage.However it is shared also between iframes in the exact same tab. This is after assumingthat they come from the same origin. The data thus, survives a page refresh. But it doesn’t survive opening or closing the tab.

Angular Session Storage

Simple angular application can be created with localstorage. Applications such as these use web storage service plug-in to store variable data into the browser, which enables theusage of HTML 5 local storage, Angular Session storage or in memory mechanism in order to store data. Implementation of sessionstorage and local storage into angular is an easy process.

One can store data into server side. However it is expensive in terms of application performance. Every time one needs to fetch data from the server, this option can be usedin case it has a security risk forstoring data on the client side.

In case one must be used on Redis, it must be kept in mind that Redis on shared hosting environment is not possible. Without root access, it is not going to be installed. Host Gator will also not entertain the request to install Redis on their shared hosting server.

The best way is to go to the VPS hosting in case onewishes to install it. Installing Redis is not a complex work.