用于缓存的 Nativescript 插件

Nativescript Plugin for Caching

是否有用于数据缓存的积极维护的 nativescript 插件?

喜欢nativescript-cache,但遗憾的是这个插件现在不活动了。

您可以使用 nativescript 核心模块 application-settings。它与 nativescript-cache 插件完全相同。

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");

有关更多信息,您可以参考 nativescript 文档:https://docs.nativescript.org/angular/code-samples/application-settings