...

The Request/Response object pairs that are cached in long-term memory have permanent storage options thanks to the Cache interface (JS Cache). Although a Cache object’s lifespan depends on the browser, scripts from a single origin may usually rely on the existence of a previously populated Cache object. It should be noted that workers and windowed scopes may both use the Cache interface. Although it is described in the service worker specification, you are not required to utilize it in connection with service workers.

What is window.localStorage? The localStorage read-only property of the window the interface allows you to access a Storage object for the Document’s origin; the stored data is saved across browser sessions. 

This is the code I wrote. You can copy it or clone it to your machine. It can be changed to suit your needs.

class Cache_Reuse {
    constructor() { }
    StoreJsonData(key, jsonData) {
        window.localStorage.setItem(key, JSON.stringify(jsonData));
    }
    GetJsonData(key) {
        let data = window.localStorage.getItem(key);
        if (data == null) return null;
        return JSON.parse(data);
    }
    RemoveItem(key) {
        window.localStorage.removeItem(key);
    }
    Clear() {
        window.localStorage.clear();
    }
}
const cache = new Cache_Reuse();

Link: https://github.com/albert18/cache-js.git


For more information, please visit the official Developer Mozilla website.

Want to read more about the Top 5 Programming Languages? Click here.

Ser

Military Veteran | Software Engineer | Cloud Engineer | & Cybersecurity Enthusiast

By Ser

Military Veteran | Software Engineer | Cloud Engineer | & Cybersecurity Enthusiast

Seraphinite AcceleratorBannerText_Seraphinite Accelerator
Turns on site high speed to be attractive for people and search engines.