Nativescript Plugin for Caching

Issue

Is there an actively maintained nativescript plugin for data caching?

like nativescript-cache but sadly this plugin is now inactive.

Solution

you can use nativescript core module application-settings. it does exactly same as nativescript-cache plugin.

import {
    getBoolean,
    setBoolean,
    getNumber,
    setNumber,
    getString,
    setString,
    hasKey,
    remove,
    clear
} from "application-settings";

Set and get boolean value and provide default value in case it is not set

setBoolean("isTurnedOn", true);
this.isTurnedOn = getBoolean("isTurnedOn", true);

Set and get string value

setString("username", "Wolfgang");
this.username = getString("username");

Set and get numeric value.

setNumber("locationX", 54.321);
this.locationX = parseFloat(getNumber("locationX").toFixed(3));

Reading values that are not set before while providing default value

// will return "No string value" if there is no value for "noSuchKey"
this.someKey = getString("noSuchKey", "No string value");

for more information you can refer nativescript docs: https://docs.nativescript.org/angular/code-samples/application-settings

Answered By – bhavin jalodara

Answer Checked By – David Marino (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.