ElStorage class abstract

本地存储抽象类,在执行 El.init 方法时会初始化所有必要的本地存储,包括:localStoragesessionStorage, 除此之外,你还可以自定义多个相互隔离的 Storage 对象:

void main() async {
  await El.init();
  final myStorage = await el.storage.createStorage('my_storage');
}

注意:ElStorage 不能存储大量数据,因为在浏览器上它的最大容量只有 5 M, 虽然在客户端上没有容量限制,但单个 Storage 存储的数据也不宜过大, 因为每次存储都是直接对整个 Map 进行序列化,存储的数据过多会引起性能问题!

Constructors

ElStorage(String key, Map<String, dynamic> data)

Properties

data Map<String, dynamic>
本地存储对象,默认情况下,数据直接以 key - value 存储,但如果设置了缓存时间, 那么 value 会再包裹一层 Map,其结构包含 2 个关键 key:expireKeyexpireDataKey
final
debounceSerialize VoidCallback
对序列化进行防抖处理,避免频繁序列化操作
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
key String
用于区分多个存储对象
final
length int
存储的 key 数量
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

clear() → void
清空数据
clearExpire() List<String>
清除已过期的数据
getExpires() List<String>
获取过期 key 集合
getItem<T>(String key, {ElSerialize? serialize}) → T?
获取数据
hasKey(String key) bool
检查是否存在 key 数据
isExpire(String key, {bool includeNull = true}) bool
判断数据是否已过期
isExpireData(dynamic result) bool
判断当前数据是否携带过期对象
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
removeItem(String key) → void
删除数据
removeMultiItem(Iterable<String> keys) → void
批量删除数据
serialize() → void
本地序列化
setExpire(String key, Duration expire, {bool includeUpdate = true}) → void
给已有的数据设置过期时间
setItem<T>(String key, T value, {ElSerialize? serialize, Duration? expire}) → void
设置数据
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Constants

expireDataKey → const String
expireKey → const String