Thursday, April 11, 2019

LocalStorage, SessionStorage or Native Session (Angular 7 or greater)

I share example how to integrate LocalStorage, SessionStorage or Native session storage, Native local storage.

LocalStorage: If you create  local storage value, the value exist on the browser.
SessionStorage: If you create session storage value, the value exist just current tab browser, if you open new tab the value doesn't exist.

Native session is similar concepts, but you don´t need to install anything. check in the end the blog. I recommed use native session or native local storage.

Use ngx-webstorage


1. Install on project angular.

npm install --save ngx-webstorage

2. Add app.module.ts

imports: [
NgxWebstorageModule.forRoot(),
]

3.  Import on your component

import {LocalStorageService, SessionStorageService} from 'ngx-webstorage';

4. Add on your constructor

constructor(private localSt:LocalStorageService,
private sessionSt:SessionStorageService) {}


5. Examples

/*Set*/

this.localSt.store("keyLocal", "value");
this.sessionSt.store("keySession", "2");

/*Get*/

this.localSt.retrieve("keyLocal");
this.sessionSt.retrieve("keySession");


/*remove*/
this.localSt.clear("keyLocal");
this.sessionSt.clear("keySession");


Native session or local storage javascript


*add*
sessionStorage.setItem("YOUR_KEY", YOUR_VALUE)

*Get*
sessionStorage.getItem("YOUR_KEY")

*Remove*
sessionStorage.removeItem("YOUR_KEY")


*add*
localStorage.setItem("YOUR_KEY", YOUR_VALUE)

*Get*
localStorage.getItem("YOUR_KEY")

*Remove*
localStorage.removeItem("YOUR_KEY")












Virtual Threads in Java 21: Simplified Concurrency for Modern Applications

  With Java 21, Virtual Threads have redefined how we approach concurrency, offering a lightweight and efficient way to handle parallel and ...