-
Notifications
You must be signed in to change notification settings - Fork 124
/
ExpiringStorage.ts
32 lines (30 loc) · 1023 Bytes
/
ExpiringStorage.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import type { KeyValueStorage } from './KeyValueStorage';
/* eslint-disable @typescript-eslint/method-signature-style */
/**
* A KeyValueStorage in which the values can expire.
* Entries with no expiration date never expire.
*/
export interface ExpiringStorage<TKey, TValue> extends KeyValueStorage<TKey, TValue> {
/**
* Sets the value for the given key.
* Should error if the data is already expired.
*
* @param key - Key to set/update.
* @param value - Value to store.
* @param expiration - How long this data should stay valid in milliseconds.
*
* @returns The storage.
*/
set(key: TKey, value: TValue, expiration?: number): Promise<this>;
/**
* Sets the value for the given key.
* Should error if the data is already expired.
*
* @param key - Key to set/update.
* @param value - Value to store.
* @param expires - When this value expires. Never if undefined.
*
* @returns The storage.
*/
set(key: TKey, value: TValue, expires?: Date): Promise<this>;
}