npm i --save nativescript-cache
- 版本:1.0.0
- GitHub: https://github.com/pocketsmith/nativescript-cache
- NPM: https://npmjs.net.cn/package/nativescript-cache
- 下载量
- 昨日: 0
- 上周: 2
- 上个月: 10
nativescript-cache
nativescript-cache 是 NativeScript 的持久缓存插件。使用它来存储任意数据以实现快速访问。
基于 iOS 的 TMCache 和 Android 的 SharedPreferences 构建。
安装
tns plugin add nativescript-cache
使用
缓存插件支持以下方法
get(key)
set(key, value)
delete(key)
clear
请注意,缓存条目的值 必须是字符串。如果您想存储复杂数据,请在将数据放入缓存之前使用 JSON.stringify
,并在取出数据时使用 JSON.parse
。
var cache = require("nativescript-cache");
cache.set("key1", "val1");
cache.get("key1"); // "val1"
cache.delete("key1");
cache.get("key1"); // undefined
cache.set("key2", "val2");
cache.set("key3", "val3");
cache.clear();
cache.get("key3"); // undefined