过期时间插件。

Since

2.0.0

Example

import { StorageWrap, ExpiresPlugin } from '@just4/storage';
const storage = new StorageWrap('local', {
plugins: [new ExpiresPlugin('local')]
});
storage.set('test-01', '1', { expires:
new Date(2023, 11, 1)
}); // 2023 年 12 月 1 日 00:00:00 过期
storage.set('test-02', '1', {
expires: '1 day'
}); // 当前时间的 1 天后过期
storage.set('test-03', '1', {
expires: '5 secs'
}); // 当前时间的 5 秒后过期
storage.get('test-03'); // '1'
setTimeout(() => {
storage.get('test-03'); // null
}, 6000);

Type Parameters

Hierarchy

Constructors

Properties

_options: IStorageOptions

存储包装的选项。

_plugins: StorageWrap<object>[] = []

存储所有插件。

_storage: SimpleWrap

使用的存储对象。

available: boolean

当前存储对象是否有效(如果获取存储对象出现异常,则无效)。

Methods

  • 获取指定存储项的值并解析为 JSON。

    Parameters

    • key: string

      存储项键名。

    Returns unknown

    解析结果。

  • 写入指定存储项的值。

    Parameters

    • key: string

      存储项键名。

    • value: string

      存储项的值。

    • Optional options: T

      写入操作的选项。

      Optional

    Returns void

  • 把指定值序列化为 JSON 字符串后写入到指定存储项。

    Parameters

    • key: string

      存储项键名。

    • value: unknown

      存储项的值。

    • Optional options: T

      写入操作的选项。

      Optional

    Returns void

Generated using TypeDoc