Constructor
new Storage(options)
- Source:
- storage只会管理存储通过其 API 创建的离线数据,不管理其他自定义的存储数据(数据项会加上命名空间前缀)
- storage实例会单独建立一个映射表来管理数据单元与数据的映射关系
Parameters:
Name | Type | Description |
---|---|---|
options |
object | 配置选项见Storage.options |
Members
(static, readonly) SESSIONSTORAGE :string
- Source:
- Since:
- 1.0.0
sessionStorage驱动器
Type:
- string
(static, readonly) INDEXEDDB :string
- Source:
- Since:
- 1.0.0
indexedDB驱动器
Type:
- string
(static, readonly) WEBSQL :string
- Source:
- Since:
- 1.0.0
webSQL驱动器
Type:
- string
(static, readonly) LOCALSTORAGE :string
- Source:
- Since:
- 1.0.0
localStorage驱动器
Type:
- string
(static, readonly) options :object
- Source:
- Since:
- 1.0.0
Properties:
Name | Type | Default | Description |
---|---|---|---|
maxAge |
number |
-1
|
数据可存活时间(毫秒单位),可选值有:0=不缓存,小于0的值=永久缓存(默认),大于0的值=可存活时间 |
debug |
boolean |
false
|
调试日志输出模式 |
driver |
array |
[Storage.SESSIONSTORAGE,Storage.INDEXEDDB,Storage.WEBSQL,Storage.LOCALSTORAGE
|
离线存储器的驱动器优先选择列表 |
name |
string |
'storage'
|
离线存储器命名空间 |
description |
string |
''
|
离线存储器描述,取localforage的默认值 |
size |
number |
4980736
|
离线存储器的大小,仅webSQL有效,取localforage的默认值 |
storeName |
string |
4980736
|
离线存储器的数据库名称,仅indexedDB和WebSQL有效,取localforage的默认值 |
默认配置选项
Type:
- object
(readonly) $storeMap :object
- Source:
- Since:
- 1.0.0
实例的数据与存活时间映射关系表
Type:
- object
(readonly) $options :object
- Source:
- Since:
- 1.0.0
实例初始配置项
Type:
- object
(readonly) $maxAge :number
- Source:
- Since:
- 1.0.0
实例的数据存活时长
Type:
- number
(readonly) $driver :string
- Source:
- Since:
- 1.0.0
实例的驱动器类型
Type:
- string
(readonly) $name :string
- Source:
- Since:
- 1.0.0
实例的命名空间
Type:
- string
(readonly) $description :string
- Source:
- Since:
- 1.0.0
实例的描述
Type:
- string
(readonly) $size :number
- Source:
- Since:
- 1.0.0
实例的数据库大小
Type:
- number
(readonly) $storeName :string
- Source:
- Since:
- 1.0.0
实例的数据库名称
Type:
- string
(readonly) $length :number
- Source:
- Since:
- 1.0.0
实例的数据项长度
Type:
- number
(readonly) length :number
- Source:
- Since:
- 1.0.0
获取实例的数据项长度,实例$length属性的别名属性
Type:
- number
Methods
(static) config(options) → {Storage}
- Source:
- Since:
- 1.0.0
- See:
更新默认配置选项
Parameters:
Name | Type | Description |
---|---|---|
options |
object | 配置选项见Storage.options |
Returns:
- Type
- Storage
(async, static) supports(driver) → {Promise}
- Source:
- Since:
- 1.0.0
判断浏览器是否支持对应的离线存储驱动器
Parameters:
Name | Type | Description |
---|---|---|
driver |
Symbol | 驱动器常量 |
Returns:
- Type
- Promise
(async) ready() → {Promise}
- Source:
- Since:
- 1.0.0
确保实例已初始化完成
Returns:
- Type
- Promise
(async) driver() → {Promise}
- Source:
- Since:
- 1.0.0
获取当前实例的驱动器常量
[注] 确保实例已初始化完成,否则取不到值
Returns:
- Type
- Promise
(async) setItem(name, data, options) → {Promise}
- Source:
- Since:
- 1.0.0
存储数据项到离线存储器
Parameters:
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
name |
string | 数据项名称 |
||||||||||||
data |
* | 任意数据 |
||||||||||||
options |
object | 自定义存储单元实例的配置选项 Properties
|
Returns:
- Type
- Promise
(async) getItem(name) → {Promise}
- Source:
- Since:
- 1.0.0
获取指定数据项数据
Parameters:
Name | Type | Description |
---|---|---|
name |
string | 数据项名称 |
Returns:
- Type
- Promise
(async) removeItem(name) → {Promise}
- Source:
- Since:
- 1.0.0
移除数据项
Parameters:
Name | Type | Description |
---|---|---|
name |
string | 数据项名称 |
Returns:
- Type
- Promise
(async) clear() → {Promise}
- Source:
- Since:
- 1.0.0
清空所有数据项
Returns:
- Type
- Promise
(async) keys() → {Promise}
- Source:
- Since:
- 1.0.0
获取所有时效性活的数据的键列表
Returns:
- Type
- Promise
(async) iterate(iteratorCallback) → {Promise}
- Source:
- Since:
- 1.0.0
迭代所有数据项
Parameters:
Name | Type | Description |
---|---|---|
iteratorCallback |
function | 迭代函数,迭代函数若返回了具体的值,则提前退出,且返回值将作为resolved的结果值 |
Returns:
- Type
- Promise